@echo off setlocal enabledelayedexpansion enableextensions echo %~f0 version 2.0.1 echo Iterates through subdirs to do "md5check.bat" at each subdir. if {%1} equ {} ( set command=md5check set command2=dir md5.output.txt /s/b echo. echo Here is the list of md5.output.txt files that will be checked by invoking the following command^: echo !command2! echo. call !command2! ) set command set cd_original=!cd! @echo. Echo Here is the list of commands that will be executed^: for /f "usebackq delims=<|>" %%a in (`%command2%`) do ( if /I %command% equ md5check ( set command3=cd /d "%%~dpa" ) echo !command3! !command3! echo !cd! echo call !command! call !command! ) echo. echo. echo Starting the repeating commands... echo. echo. goto :DONE for /f "usebackq delims=<|>" %%a in (`%command2%`) do ( if /I %command% equ md5check ( set command3=cd /d "%%~dpa" ) else ( echo. set command3=cd /d "%%~a" ) echo !command3! !command3! echo %cd% echo call %command% call %command% ) goto :DONE :HELP echo md5RepeatDirs.bat echo Batch file that runs md5 repeatedly in the subdirs where it finds md5.output.txt files. echo. goto :DONE :DONE cd /d "%cd_original%"