Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for which.bat

(view source code of which.bat as plain text)

  1. @ECHO OFF
  2. :: Command line error check:
  3. IF "%1"=="" GOTO Syntax
  4.  
  5. :: Check PATH length:
  6. SET TEST=
  7. FOR %%A IN (.\;%PATH%) DO SET TEST=OK
  8. CLS
  9. IF NOT "%TEST%"=="OK" GOTO StrLength
  10.  
  11. :: The actual program:
  12. ECHO.
  13. FOR %%A IN (.\;%PATH%) DO IF EXIST %%A.\%1.BAT TRUENAME %%A.\%1.BAT
  14. FOR %%A IN (.\;%PATH%) DO IF EXIST %%A.\%1.EXE TRUENAME %%A.\%1.EXE
  15. FOR %%A IN (.\;%PATH%) DO IF EXIST %%A.\%1.COM TRUENAME %%A.\%1.COM
  16. FOR %%A IN (.\;%PATH%) DO IF EXIST %%A.\%1     TRUENAME %%A.\%1
  17. GOTO End
  18.  
  19. :: PATH length error message:
  20. :StrLength
  21. ECHO.
  22. ECHO Sorry, your PATH environment variable is too long to
  23. ECHO be handled by this batch file.
  24. ECHO.
  25. ECHO The 127 character command line limit was exceeded
  26. ECHO when just testing.
  27. GOTO End
  28.  
  29. :: Help screen:
  30. :Syntax
  31. ECHO.
  32. ECHO WHICH, Version 1.00
  33. ECHO UNIX-like WHICH utility for DOS
  34. ECHO Written by Rob van der Woude
  35. ECHO.
  36. ECHO Usage:  WHICH  program_name
  37. ECHO.
  38. ECHO You may specify program_name with or without extension,
  39. ECHO but without a drive or path.
  40. ECHO Spaces or wildcards aren't allowed either.
  41. ECHO.
  42. ECHO Limitation: This batch file has problems handling long
  43. ECHO             PATH variables; it will say so, however,
  44. ECHO             when it encounters this problem.
  45.  
  46. :End
  47. ECHO.
  48. SET TEST=
  49.  

page last modified: 2024-04-16; loaded in 0.0078 seconds