I am trying to have a bat file in folder1
which is the parent folder, and this bat file which named run.bat
will loop through all subfolders, and invok
My guess is that the script must be able to consistently change directories from the same place where the for
loop was invoked. Just saving the current folder (via a pushd
) and restoring it after the child invocation (via popd
) should be enough.
@echo off
FOR /d /r %%i IN (*) DO (
pushd "%%i"
call "child.bat"
popd
)
Based upon your extra information in the comments, this should work for you.
@echo off
FOR /d /r %%i IN (*) DO (
if exist "%%i\child.bat" start "" /d "%%i" "%comspec%" /c "child.bat"
)