Batch file to search all drives for a file

Soldato
Joined
17 Jul 2008
Posts
7,392
All I want to do is search c,d,e,f,g,h,etc for a file then set an environment variable to be the drive letter the file was found on

I can do it with a for / do / dir file name / errorlevel check but when it gets to a cd drive it stops with a pop up "cmd.exe no disk in drive" it would not matter only it stops the batch file running until you click cancel
 
It's been a long time since I wrote batch files but off the top of my head sometihng along these lines might help

for %t in (file1.ext file2.ext file3.ext) do if not exist %t do path=%path%;./

or something ... my syntax is probably off as i've not written a batch file since the early 2000s.
 
I did it in the end by setting a registry key

hklm\system\currentcontrolset\control\windows dword ErrorMode set to 2

with this set I can search all drives in a batch file and if it hits a CD drive with no media (or card reader) it does not stop with a popup it carries on..

Now my autoinstall batch file can be run from CD/network/usb stick and it can detect where it was run from...

I could have used %0 to get the full patch of the batch file only its always initiated from c:\...\startup it then finds the "install point" be it network, or local drive letter...
 
Back
Top Bottom