2

Say, I have 20 folders named folder0 to folder20 and inside each folder I have a test.bat file. I want to run all the batch files inside each folder at a time through another batch file. If I use the following batch file, it will run the test.bat inside each folder one after another:

FOR /L %%A IN (0,1,20) DO (
 cd folder%%A
 call test.bat 
 cd..
) 

But how will I run the batch files inside each folder parallely?

user76289
  • 85
  • 1
  • 5
  • 2
    Sometimes even the experts get on the wrong track ;-) Simply replace `call` with `start` in your batch. You know you'll get 21 windows? –  Oct 29 '16 at 17:21

2 Answers2

0

I don't think there's another way than iterating through a list or using indicies as a part of the path you want to use. There's no built-in way to just run each .bat available in a folder recursively.

You can however use something like this to fetch the path into a for-loop variable and then do:

call %%X\test.bat

Example:

FOR /F %%A IN ('dir /ad /b /s') DO (
 echo %%A\test.bat
 call %%A\test.bat 
)

Echo that even to see what is launched where.

Community
  • 1
  • 1
Peter Badida
  • 11,310
  • 10
  • 44
  • 90
-1

Perhaps:

For /R %%A In (t?st.bat) Do Start "%%~nA" /D"%%~dpA" "%%~A"

…just make sure that the script is run from the directory holding your twenty numbered folders.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • 1
    `for /R` does not search the file system for `test.bat` as there are no wildcards in between `()`, it merely enumerates the entire directory tree recursively and appends `test.bat` to each item; in addition, the OP does not want to search for `test.bat` recursively but in one directory level only; to overcome all that, use `for /D %%D in (folder*) do for /F %%F in ('dir /B test.bat') do start "" /D "%%~dpF" "%%~F"`, for instance... – aschipfl Oct 29 '16 at 17:07