I have folders like E:\Backups\code\Hazard\test1 ... testn
And inside these test folders something like E:\Backups\code\Hazard\test1\it0 ... itn
The root folder is E:\Backups\code from where the code runs.
The below code runs on each subfolders and copies summary.yml from it0 folder to latest it(n) folder.
Why the code runs just for test1 folder and then hangs?
setlocal ENABLEDELAYEDEXPANSION
set root=%cd%
for /D %%X in (%root%\*) do (
echo %%X
cd %%X
for /D /r %%b in (*) do (
cd %%b
echo %%b
for /f "tokens=1,2,*" %%a in ('robocopy . . file.txt /l /nocopy /is /s /nc /ns /ts /ndl /njh /njs ^| sort /r') do set "lastFolder=%%~dpc" & goto :done
:done
echo Last folder : %lastFolder%
for /d %%j in (*) do (
if /i "%%~nj"=="it0" COPY %%j\summary.yml %lastFolder%
)
cd ..
)
)