"Which" command under Windows

  

Under Linux, there is a command called which, which can find the directory where a command is located in Path and display it. Under Linux: [adam@i ase adam]$ which ls /bin/ls [adam@i ase adam]$ which rm /bin/rm There is a where.exe in the NT Resource Kit, which has the same effect, but The Resource Kit is a fee, and here we can make a batch file to do this.

Use Notepad to edit a which.bat and store it in a directory in the Wit directory or other Path variable. The contents of the batch file are as follows: @echo off Rem Check command line parameters if { %1}=={} goto :Usage for %%ii ({ {/{-) do if {%1}==%%i?} goto :Usage %%i echo. :Rem Check in the current directory to see if The file exists for %%ii (%1) do if exist %%~nx%i ( echo %%~Fi goto :EOF ) :Rem Check the file in Path for %%ii (%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 test our program: Microsoft Window 2000 [Versio 5.00.2195] (C) Copyright 1985-1998 Microsoft Corp. C:\\>which WHICH quot;filename" Input file, return the file The full path! C:\\>which cmd.exe C:\\WI T\\system32\\cmd.exe C:\\> OK, the test passed!

Copyright © Windows knowledge All Rights Reserved