Batch file to search for a file and run it

Intel Core i5 i5-650 3.20 ghz processor...
July 8, 2010 at 21:02:28
Specs: Windows Vista
I need a batch file that will search the computer's
drives for a file (start.bat) and then execute it.

See More: Batch file to search for a file and run it

Report •


#1
July 9, 2010 at 08:11:27

@echo off
for /f "tokens=*" %%a in ('dir start.bat /b /s') do (
  call %%a)


Report •

#2
July 9, 2010 at 15:45:09
Um, that only works if the start.bat is in the same directory as
the other batch is. I need it to be in another drive and find
start.bat in another drive. But thanks for trying to help. What I'm
trying to do is have the batch (let's call it find.bat) that is in a cd
drive find start.bat, which is in the root of a usb drive and execute
it. Does that make sense?

Report •

#3
July 9, 2010 at 16:33:07
::21882.bat
@ECHO OFF
SETLOCAL 

FOR /L %%a IN (2,1,3) DO (
    FOR /F "tokens=2 delims==" %%b IN ('WMIC LogicalDisk Where "DriveType=%%a" Get DeviceID /Format:List') DO (
        FOR /F "tokens=*" %%c IN ('DIR %%b\start.bat /b /s') DO (
            CALL "%%c"
        )
    )
)

EXIT /B

If you wanted only USB drives, eliminate the outer FOR /L loop, and specify DriveType=2. I have the above searching for Removable (2) and Local Fixed Disk (3) drives. Network drives are 4, CD/DVD drives are 5.

Insomniac at large


Report •

Related Solutions

#4
July 9, 2010 at 16:39:00
Sorry, it's telling me Invalid GET expression.

Report •

#5
July 9, 2010 at 16:41:41
Oh wait hold on I didn't read that last part you said, I'll see if it'll
work now

Report •

#6
July 9, 2010 at 16:42:07
Dunno where the slash went :-/

format:list

should be:

/format:list

I fixed Response 3.

Insomniac at large


Report •

#7
July 9, 2010 at 16:51:52
THANK YOU SO MUCH IT WORKED :D

Report •

Ask Question