简化robocopy批处理以尝试多个驱动器号

时间:2017-01-21 04:40:22

标签: batch-file

我创建了一个批处理文件,用于从一个驱动器到另一个驱动器运行ondemand robocopy。问题是外部驱动器并不总是具有相同的字母。

这是代码。该文件有效,并为我提供了我期望的行为。我想知道是否有办法简化这一点。

:: This is my robocopy script
IF EXIST "E:\Appraisal Service" goto robocopy1 else goto nextdrive1 

:robocopy1
robocopy "Z:\Appraisal Service" "E:\Appraisal Service" /E

:nextdrive1
IF EXIST "F:\Appraisal Service" goto robocopy2 else goto nextdrive2

:robocopy2
robocopy "Z:\Appraisal Service" "F:\Appraisal Service" /E

:nextdrive2
IF EXIST "G:\Appraisal Service" goto robocopy3 else goto nextdrive3

:robocopy3
robocopy "Z:\Appraisal Service" "G:\Appraisal Service" /E

:nextdrive3
IF EXIST "H:\Appraisal Service" goto robocopy4 else goto nextdrive4

:robocopy4
robocopy "Z:\Appraisal Service" "H:\Appraisal Service" /E

:nextdrive4
IF EXIST "I:\Appraisal Service" goto robocopy5 else goto nextdrive5

:robocopy5
robocopy "Z:\Appraisal Service" "I:\Appraisal Service" /E

:nextdrive5
IF EXIST "J:\Appraisal Service" goto robocopy6 else goto nextdrive6

:robocopy6
robocopy "Z:\Appraisal Service" "J:\Appraisal Service" /E

:nextdrive6
IF EXIST "K:\Appraisal Service" goto robocopy7 else goto quit

:robocopy7
robocopy "Z:\Appraisal Service" "K:\Appraisal Service" /E

:quit
exit

提前致谢

2 个答案:

答案 0 :(得分:0)

for %%a in (E F G H I J K) do IF EXIST "%%a:\Appraisal Service" robocopy "Z:\Appraisal Service" "%%a:\Appraisal Service" /E

%%a依次设置为每个目标驱动器号,如果目标驱动器号上存在该目录,请执行复制。

答案 1 :(得分:0)

这是最终的代码。感谢Magoo(谁是正确的)。我弄清楚了我的不幸(我错过了一个“:”导致它无法正常工作)。

(web -> public_html)