如何在批处理脚本中中断一个 "for /l" 循环?
如何在批处理脚本中中断一个 "for /l" 循环?
我是一个对Windows批处理命令不熟悉的新手。
我有一个关于批处理文件的问题。
如何跳出"for /l"循环?
在下面的脚本中,我想要从一个文件夹复制x个文件到另一个文件夹。
然而,在跳出第一个循环后,第二个循环没有正常工作,
它将源文件夹中的所有文件都复制到目标文件夹中。
谢谢你的帮助 🙂
@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 将文件复制到Target3 ) )