1.

Solve : Find occurences of programs in the DOS path?

Answer»

Does anyone know of a MS or 3rd party utility that will look at the DOS path, then search all entries in that path for occurrences of a program file, including folders on network drives.

For example, say my path is C:\;F:\UTILS and I am looking for an exe called EXPLORER.EXE, and EXPLORER.EXE lives in both of those folders, and also lives in C:\JUNK. Is there a utility that would locate EXPLORER.EXE in C:\ and F:\UTILS, but ignore the occurrence of EXPLORER.EXE in C:\JUNK, since that is not in my path?

Thanks,
Curt
This fall into the Stupid DOS Tricks category:

Code: [Select]
@echo off
if .%2==. for /f "tokens=1-26 delims=;" %%a in ("%path%") do (set pgm=%1 & call %0 %%a %%b %%c %%d %%e %%f %%g %%H %%i %%j %%k %%l %%m %%n %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z)

:loop
if .%1==. goto end
if exist %1\%pgm% echo Program %pgm% found in: %1
shift
goto loop

:end
set pgm=


Only checks FIRST 26 directories on PATH. Pass the file you're looking for as the first command line parameter.

Thanks Sidewinder... for a "stupid DOS trick", that's one smart little bat file!
The only problem is when the entire path contains a space (like Program Files), your bat file parses out each word as a separate folder to search.

I put double quotes around each of the variables to look like "%%a" "%%b", etc, and it works to keep the string together, except that for some reason the "if exist" line always tests positive therefore thinking it found a file called "" and displaying the message Program xxxxx.xxx found in "". It kind of works, but doesn't quite know how to test for the null string WITHIN double quotes.

Thanks again!
It was too much of a challenge for my one living brain cell to remember the alphabet again. This might be somewhat more readable:

Code: [Select]
@echo off
set var=%path%

:loop
if "%var%"=="" goto :next
for /f "tokens=1* delims=;" %%i in ("%var%") do (
set var=%%j
echo %%i>>Temp
)
goto loop

:next
for /f "delims=;" %%a in (Temp) do (
if exist "%%a\%1" echo Program %1 located in: %%a
)
DEL Temp
set var=


This solution cries out for a script where you can apply the KISS method (don't ask). Next time please mention your OS.

I'm using XP SP2.

Your latest bat file is slick. But for some reason (maybe because I use XP), I have to check for a space instead of a null:

Changed if "%var%"=="" goto :next
To if "%var%"==" " goto :next

for the IF to ever pass. Works GREAT. Thanks!



Discussion

No Comment Found