Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
February 11, 2004
I have scripted RunFolder.bat to run a batch file on all the sub-folders of a parent folder that match a specified mask.
The syntax for using RunFolder.bat is:
RunFolder StartPath SubFolder Batch
Where:
StartPath is the fully qualified path to the parent folder.SubFolder is the mask used to find sub-folders.Batch is the fully qualified batch file name to run, passing it the fully qualified name of the sub-folder.
RunFolder.bat contains:
@echo offsetlocalif {%3}=={} goto syntaxset folder=%1#set folder=%folder:"=%set folder=%folder:#=%set folder=%folder:#=%if not exist "%folder%*.*" goto syntaxset sub=%2set sub=%sub:"=%if not exist %3 goto syntaxset batch=%3for /f "Tokens=*" %%d in ('dir "%folder%" /b /s /ad ^|Findstr /I /c:"%sub%"') do call :isSub "%%d"endlocalexit /b 0:syntax@echo Syntax RunFolder StartPath SubFolder Batchendlocalexit /b 1:isSubset dir=%1set parent=%~DP1call set work=%%dir:%parent%=%%if /i %work% NEQ "%sub%" goto :EOFcall %batch% %dir%
You May Also Like