(view source code of which.bat as plain text)
@ECHO OFF
:: Command line error check:
IF "%1"=="" GOTO Syntax
:: Check PATH length:
SET TEST=
FOR %%A IN (.\;%PATH%) DO SET TEST=OK
CLS
IF NOT "%TEST%"=="OK" GOTO StrLength
:: The actual program:
ECHO.
FOR %%A IN (.\;%PATH%) DO IF EXIST %%A.\%1.BAT TRUENAME %%A.\%1.BAT
FOR %%A IN (.\;%PATH%) DO IF EXIST %%A.\%1.EXE TRUENAME %%A.\%1.EXE
FOR %%A IN (.\;%PATH%) DO IF EXIST %%A.\%1.COM TRUENAME %%A.\%1.COM
FOR %%A IN (.\;%PATH%) DO IF EXIST %%A.\%1 TRUENAME %%A.\%1
GOTO End
:: PATH length error message:
:StrLength
ECHO.
ECHO Sorry, your PATH environment variable is too long to
ECHO be handled by this batch file.
ECHO.
ECHO The 127 character command line limit was exceeded
ECHO when just testing.
GOTO End
:: Help screen:
:Syntax
ECHO.
ECHO WHICH, Version 1.00
ECHO UNIX-like WHICH utility for DOS
ECHO Written by Rob van der Woude
ECHO.
ECHO Usage: WHICH program_name
ECHO.
ECHO You may specify program_name with or without extension,
ECHO but without a drive or path.
ECHO Spaces or wildcards aren't allowed either.
ECHO.
ECHO Limitation: This batch file has problems handling long
ECHO PATH variables; it will say so, however,
ECHO when it encounters this problem.
:End
ECHO.
SET TEST=
page last modified: 2024-04-16; loaded in 0.0078 seconds