|
Answer» I know that you can execute a DOS command in sub-directories by using the /s switch at the end of a command.
Is there an equivalent way of executing a DOS batch file in sub-directories as well. I tried the command: foo.bat /s without success.
BrianLike all switches, the /s switch works with some (not all) Windows commands, namely those are specifically WRITTEN to respond to it. It is not a magic switch that makes any program or script recurse through directory trees. If you want to process EVERY file and/or subfolder in a tree you can USE techniques like (for example) FOR /F %%F in ('dir /s') do [whatever] but really if you want meaningful advice you need to be a bit less coy about what it is you are TRYING to do. THANKS for the suggestion of using the for loop.
Each of my sub-directories each had a batch file with an identical name, let's call it "hello_world.bat".
I wanted to traverse the directory structure and execute each "hello_world.bat" file
In the top subdirectory, I placed the following command in a different batch file, let's call it "go_fish.bat".
for /r %%X in (hello_world.bat) do (call "%%X")
Thanks for the help.
Brian
@brian642, you can use for /f + dir to traverse the directory: Code: [Select]@echo off for /f "delims=" %%X in ('dir /s /b "hello_world.bat"') do ( echo "%%X" ) pause If you prefer to user for /r, you may need a wild char (* or ?) to catch the target batch file: Code: [Select]@echo off for /r %%X in (hello_world.bat?) do ( echo "%%X" ) pause
|