Thursday, 24 August 2017

Batch to open files with the same extension in sub-folders in Windows


I need to open a large number of files that have the same extension in one folder; these files are also in sub-folders inside this one folder.


How do I open all of them using CMD. The files are self-executable since they're .bat files and each executes specific commands when I double click them manually.



Answer



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



No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...