【发布时间】:2011-03-16 06:36:00
【问题描述】:
每当我在下面运行code 时,我都会在使用 if exists 行时出错,因为无论目录是否存在,它都好像该行从未存在过......要么或者它没有读取 else 行。
echo off
echo
echo (c) Ryan Leach 2010
echo Stockmaster Backup System for exclusive use of Riverland Paper Supplies
echo
echo Please ensure that all computers are out of stock master to the windows xp screen
echo and that the backup usb with the day of the week labeled on it is inserted
pause
IF EXIST D:\RPS_BACKUP\backups_to_zip\ goto zipexist else goto zipexistcontinue
:zipexist
IF EXIST d:\RPS_BACKUP\backups_old\ rd /s /q D:\RPS_BACKUP\backups_old
echo backup did not complete last time, backup will restart from zip-usb phase.
pause
call zip
goto tidyup
:zipexistcontinue
IF EXIST D:\RPS_BACKUP\backups_old\ goto oldexists else oldexistscontinue
:oldexists
IF EXIST d:\RPS_BACKUP\backup_temp\ rename D:\RPS_BACKUP\backups_temp backups_to_zip
rd /s /q D:\RPS_BACKUP\backups_old
echo backup did not complete last time, backup will restart at the zip to usb phase.
pause
call zip
goto tidyup
:oldexistscontinue
IF EXIST D:\RPS_BACKUP\backups_temp\ goto tempexists else goto tempexistscontinue
:tempexists
IF EXIST D:\RPS_BACKUP\backups_old\ goto backupfailed else goto tempexistscontinue
:backupfailed
@rd /s /q D:\RPS_BACKUP\backups_temp
echo backup did not complete last time, backup will restart from start.
pause
:tempexistscontinue
md D:\RPS_BACKUPS\backups_temp
xcopy \\user1\c\* D:\RPS_BACKUP\backups_temp\user1\c /h /e /z /f /r /i /s /k
IF NOT ERRORLEVEL == 1 GOTO ErrorHandler
xcopy C:\* D:\RPS_BACKUP\backups_temp\user2\c /h /e /f /r /i /s /k
IF NOT ERRORLEVEL == 1 GOTO ErrorHandler
xcopy \\user3\c\* D:\RPS_BACKUP\backups_temp\user3\c /h /e /z /f /r /i /s /k
IF NOT ERRORLEVEL == 1 GOTO ErrorHandler
call sub
call zip
:tidyup
rename D:\RPS_BACKUP\backups_to_zip backups
pause
goto :eof
:ErrorHandler
echo xcopyerrorcode is ERRORLEVEL contact ryan
pause
【问题讨论】:
-
检查目录的权限?
-
权限很好,因为目录当前不存在。目前我还不担心网络副本。
-
在第二组中,您缺少
GOTO指令。goto oldexists else oldexistscontinue -
谢谢,后来当我把它们放在下一行时,我自己注意到了。
标签: if-statement batch-file windows-xp