Give the below batch script a shot which uses a FOR /F loop and a CALL to execute each .bat
file explicitly (with a CALL) starting from the RootDir location and traverse recursively from there to find and execute all .bat
files in other subfolders beneath it.
Be sure to change the SET RootDir=C:\Folder
variable value to the folder path you need to find the .bat
files starting from it and looking through all subfolders within it which contain other .bat
files you need to execute (i.e. SET RootDir=C:\OtherFolder
).
Batch Script 1
@ECHO ON
SET RootDir=C:\Folder
FOR /F "TOKENS=*" %%A IN ('DIR /S /B "%RootDir%\*.bat"') DO CALL "%%~A"
GOTO EOF
Batch Script 2
@ECHO ON
SET RootDir=C:\Folder
CD /D "%RootDir%"
FOR /F "TOKENS=*" %%A IN ('DIR /S /B "*.bat"') DO CALL "%%~A"
GOTO EOF
Batch Script 3
@ECHO ON
SET RootDir=C:\Folder
FOR /F "TOKENS=*" %%A IN ('DIR /S /B "%RootDir%\*.bat"') DO CMD /C "%%~A"
GOTO EOF
Batch Script 4
@ECHO ON
SET RootDir=C:\Folder
FOR /F "TOKENS=*" %%A IN ('DIR /S /B "%RootDir%\*.bat"') DO START "" "%%~A"
GOTO EOF
Further Resources
%%A
and%%~A
to make those use only one percent sign so....%A
and%~A
and all should work from command line manually running that logic. Reply back when you get a chance and let me know.