Windows Batch File FOR Loop Query

GMC 1 Reputation point
2022-11-16T10:47:56.727+00:00

Hi, just looking for help from anyone familiar with Windows batch files, I’ve got the following code which is partially working but can’t figure out why the second FOR loop is failing to run. Have I made a mistake with the syntax? If I cut the first FOR loop out the second one runs but with the first loop in there the second one won’t run. Any help appreciated.

@Echo ON
echo RMSE 0.06
SET rmse=0.06
SET /P input=Enter folder to process:
echo %input%>Similar_images2.txt
md %input%\mapillary_sampled_video_frames\Similar2
@Echo OFF
SETLOCAL ENABLEDELAYEDEXPANSION

for /d %%z in (%input%\mapillary_sampled_video_frames*) do (cd %input%\mapillary_sampled_video_frames
if %%~nxz NEQ Similar (
TIMEOUT /T 1
if %%~nxz NEQ Similar2 (
powershell write-host -fore Yellow Folder = %%~nz
move /-y “%cd%%input%\mapillary_sampled_video_frames%%~nz” “%cd%%input%\mapillary_sampled_video_frames\Similar_checked%%~nz”
)
)
)

PAUSE

for /d %%G in (%input%\mapillary_sampled_video_frames\Similar_checked*) do (cd %input%\mapillary_sampled_video_frames\Similar_checked
if %%~nxG NEQ Similar (
TIMEOUT /T 1
if %%~nxG NEQ Similar2 (
powershell write-host -fore Yellow Folder = %%~nG
move /-y “%cd%%input%\mapillary_sampled_video_frames\Similar_checked%%~nG” “%cd%%input%\mapillary_sampled_video_frames%%~nG”
)
)
)

PAUSE

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,664 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,227 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Hoekstra Jelle 491 Reputation points
    2022-11-16T13:47:29.223+00:00

    Hi!
    Consider removing the PAUSE in the middle of the 2 for loops.
    Pause seems to terminate the batch file https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/pause
    I would say if there need to be a timeout consider using a timeout (https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/timeout) and an echo to mention "First loop done" or something alike.

    Hope this helps!