gpt4 book ai didi

if-statement - 如果存在 C :\directory\goto a else goto b problems windows XP batch files

转载 作者:行者123 更新时间:2023-12-04 02:41:33 28 4
gpt4 key购买 nike

每当我运行 code下面它发生在我身上,我在使用 if 存在行时犯了一个错误,因为无论目录是否存在,它都表现为该行从未存在过......

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

最佳答案

使用括号对各个分支进行分组:

IF EXIST D:\RPS_BACKUP\backups_to_zip\ (goto zipexist) else goto zipexistcontinue

在您的情况下,解析器永远不会看到 else属于 if因为 goto将愉快地接受直到命令结束的所有内容。使用 echo 时您会看到类似的问题而不是 goto .

还使用括号将允许您直接使用语句而无需跳转(尽管我无法重写您的代码以实际使用结构化编程技术;也许为时过早,或者它不适合块结构作为代码是现在)。

关于if-statement - 如果存在 C :\directory\goto a else goto b problems windows XP batch files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3253520/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com