@echo off REM (C) litchie@newsmth, Aug 15, 2007 if %1x==x goto usage set mypath=%PATH% set fullmatch=0 :continue if "%mypath%" =="" goto failend for /f "tokens=1,* delims=;" %%i in ("%mypath%") do set item=%%i& set mypath=%%j set filename=%item%\%1 REM When fully matched, it is possibly a directory REM so better not stop if exist "%filename%" set fullmatch=1&echo %filename% set filename=%item%\%1.bat if exist "%filename%" goto found set filename=%item%\%1.exe if exist "%filename%" goto found set filename=%item%\%1.cmd if exist "%filename%" goto found goto continue :FailEnd if %fullmatch%==0 echo no %1 in [%PATH%] goto end :usage echo Usage: which command echo Prints the absolute path of the command. goto end :found echo %filename% :end