Loop through folder tree and execute bat file in subfolders in parallel(accessing the files in the subfolder)

前端 未结 2 1258
死守一世寂寞
死守一世寂寞 2021-01-22 15:54

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

相关标签:
2条回答
  • 2021-01-22 16:26

    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
    )
    
    0 讨论(0)
  • 2021-01-22 16:27

    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"
    )
    
    0 讨论(0)
提交回复
热议问题