Tuesday, April 05, 2005

Where Is That Which?

Yesterday afternoon I installed Oracle 10g on my Windows notebook. After doing so, I notice that typing java on the command line run Java 1.4.2_03, while I had version 1.4.2_07 just a moment ago. So I type which java; it tells me that the java.exe is the one in \windows\system32 (apparently Oracle decided to overwrite a pre-existing copy of java.exe that I had in \windows\system32). At this point you might be wondering: What is this which command? Did't the guy say he was running on Windows? Is he using cygwin? This is no cygwin, just a batch file written by my friend and Windows guru Dan Small, and published here with his permission. How to install? Copy the code below into a file called which.bat and put the file somewhere in your PATH. Enjoy!

@echo off

if "%1" equ "" (
echo %0 file to find on path
) else if "%~nx1" neq "%1" (
echo %1
) else (
set exts=%~x1
if "!exts!" equ "" set exts=%pathext:;= %
for %%i in ( !exts! ) do (
set name=%~n1%%%i
for %%j in ( !name! ) do (
set fqn=%%~$PATH:j
if "!fqn!" neq "" (
echo !fqn!
goto :EOF

No comments: