I'm a newbie the commands of a Batch Script on Windows
I have a question about a batch file that I'm writing.
How to break from the "for /l" loop ?
In the script below, I would like to copy x number files from one folder to another
However, after the break the first loop, the second loop doesn't works fine,
it copied all files in the source folder to the destination folder.
Thank you for your help :)
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET Source=C:\Data
SET Target1=C:\Work\bak1
SET Target2=C:\Work\bak2
SET Target3=C:\Work\bak3
SET /A days=13
SET /A weekNum=9
SET /A MaxLimit=3
SET /A Count=0
for /l %%x in (1, 1, %days%) do (
if %%x LEQ 9 (
FOR /F %%G IN ('DIR /B "%Source%"\*.*') DO (
copy /y "%Source%"\"%%G" "%Target1%"
set /a Count=Count+1
if !Count!==%MaxLimit% call :step1
)
:step1
REM SET /A "x=x + 1"
REM echo %%x
IF %%x LEQ 1 IF %weekNum% EQU 9 (
FOR /F %%G IN ('DIR /B "%Source%"\*.*') DO (
copy /y "%Source%"\"%%G" "%Target2%"
set /a Count=Count+1
if !Count!==%MaxLimit% call :step2
)
:step2
REM SET /A "x=x + 1"
REM echo %%x
)
) else (
REM Copy file to Target3
)
)