我有以下代码。除了几个问题外,它工作得很好。首先,我的“如果不是空白”检查根本不起作用。其次,在每次迭代期间,它最后一次将服务器名作为服务器名和文件夹传递,我真的不明白......
代码
SET servers=server01,server02
SET drive=c
SET root=program files (x86)\test\
SET backup=%root%\backup
SET folders=folder01\,folder02\file01.txt
FOR %%b in (%servers%) do (
FOR %%a in (%folders% %%b) DO (
if not %%a == "" call :backup %%b %%a
)
)
:backup
SET currentfile="\\%1\%drive%$\%2"
setlocal
echo Backing Up %currentfile%
REM mkdir "\\%1\%drive%$\%backup%"
REM xcopy /I
exit /b
endlocal
goto :end
输出
1] Backing Up "\\server01\c$\folder01\"
2] Backing Up "\\server01\c$\folder02\file01.txt"
3] Backing Up "\\server01\c$\server01"
4] Backing Up "\\server02\c$\folder01\"
5] Backing Up "\\server02\c$\folder02\file01.txt"
6] Backing Up "\\server02\c$\server02"
7] Backing Up "\\\c$\"
如您所见,不需要第 3、6 和 7 行。