如何指定以逗号分隔的整数列表并让批处理脚本对每个整数进行循环?

如何指定以逗号分隔的整数列表并让批处理脚本对每个整数进行循环?

我目前有一个批处理脚本,我在其中使用“set /p =”。输入变量后,脚本将使用上述内容执行 3 个 robocopy 命令。3 个 robocopy 命令完成后,我使用另一个“set /p again =”询问用户是否需要再次运行此命令。有时此脚本需要针对 10-15 个整数运行。

有没有办法给出一个整数列表(以逗号分隔或其他方式),并让脚本循环返回每个后续整数?

@echo off :again echo This script will download incident data in 2 steps. echo Step 1 will attempt to download any previously archived data from your home drive. echo Step 2 will attempt to download any files from the Live Incident folder. set /p incident=Please enter the Incident Number: robocopy "\\server1\share\%incident%" "C:\local-path\%incident%" *.* /ETA /MOV /E /R:1 /W:1 /MT:3 robocopy "\\server2\share\%incident%" "C:\local-path\%incident%" *.* /ETA /E /R:1 /W:1 /MT:2 robocopy "\\server3\share\%incident%" "C:\local-path\%incident%" *.* /ETA /E /R:1 /W:1 /MT:2 set /p again=Do you have another Incident you would like to try? if /i "%again:~,1%" EQU "Y" goto again if /i "%again:~,1%" EQU "N" exit /b

答案1

@echo off
:again
echo This script will download incident data in 2 steps.
echo Step 1 will attempt to download any previously archived data from your home drive.
echo Step 2 will attempt to download any files from the Live Incident folder.

set /p "incidents=Please enter the Incident Numbers separated by a comma:"

For %%I in (%Incidents%) Do Call :Process %%I
CHOICE /C YN /M "Do you have another Incident you would like to try?"
If %ErrorLevel% Equ 1 Goto :again
Goto :Eof

:Process %1
:: you might do a range check on the Incident no. %1
Echo Processing Incedent # %1
:: while testing 
goto :Eof
robocopy "\\server1\share\%1" "C:\local-path\%casenum%" *.* /ETA /MOV /E /R:1 /W:1 /MT:3
robocopy "\\server2\share\%1" "C:\local-path\%casenum%" *.* /ETA      /E /R:1 /W:1 /MT:2
robocopy "\\server3\share\%1" "C:\local-path\%casenum%" *.* /ETA      /E /R:1 /W:1 /MT:2
Goto :Eof

如果输出看起来不错,删除goto :eof以下内容:: while testing

相关内容