Under Linux, there is a command called which, which finds the directory in the path where a command resides and displays it. Linux under:
[adam@i ase adam]$ which LS
/bin/ls
[Adam@i ASE adam]$ which RM
/BIN/RM has a where.exe in the NT Resource Kit, which has the same effect, but resource kit is charged, where we can make a batch file to implement this function.
Use Notepad to edit a which.bat and store it in a directory in the WI t directory or other path variables, and the batch file reads as follows: @echo off Rem check command line arguments
If {%1}=={} goto:usage
For%%i I ({{/{-) do if {%1}==%%i} goto:usage%%i
Echo. : Rem Check to see if the file exists in the current directory
For%%i I (% 1) do if exist%%~nx%i (
Echo%%~fi
Goto:eof
): Rem checks the file in path
For%%i I (% 1) do (
If exist%%~ $PATH: I (
echo%%~ $PATH: I
) Else (
Echo Error:%1 is not in the path!!!
Goto:usage
)
)
Goto:eof
: Usage
Echo.
echo WHICH Quot;filename "
Echo.
echo input file, return the full path of the file!
Echo.
Let's take a test of our program:
Microsoft Window [Versio 5.00.2195]
(C) All rights reserved 1985-1998 Microsoft Corp. C:>which which quot;filename "input file, return the full path of the file!"
C:>which cmd.exe C:wi Tsystem32cmd.exe c:> OK, test pass!