如果不存在C:\\目录\\转到别的一个转到b问题,Windows XP中的批处理文件 [英] IF EXIST C:\directory\ goto a else goto b problems windows XP batch files

查看:138
本文介绍了如果不存在C:\\目录\\转到别的一个转到b问题,Windows XP中的批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜每当我下面就发生在我我已经使用了一个错误,如果存在的线,无论目录是否存在运行code,它作为如果该行从未有...要么或其不读别的行。


  ECHO OFF
回声
回声(C)瑞安利奇2010
呼应Stockmaster备份系统专用的Riverland纸用品
回声
回声请确保所有计算机都缺货高手到Windows XP的屏幕
回声和用标记在其上的一周的一天的备份的USB插暂停如果不存在D:\\ RPS_BACKUP \\ backups_to_zip \\转到其他zipexist转到zipexistcontinue
:zipexist
如果不存在D:\\ RPS_BACKUP \\ backups_old \\ RD / S / Q D:\\ RPS_BACKUP \\ backups_old
回声备份没有完成最后一次,备份将重新从ZIP-USB阶段。
暂停
电话拉链
转到tidyup
:zipexistcontinue如果不存在D:\\ RPS_BACKUP \\ backups_old \\转到其他oldexists oldexistscontinue
:oldexists
如果不存在D:\\ RPS_BACKUP \\ backup_temp \\重命名D:\\ RPS_BACKUP \\ backups_temp backups_to_zip
RD / S / Q D:\\ RPS_BACKUP \\ backups_old
回声备份没有完成最后一次,备份将重新启动在压缩到USB阶段。
暂停
电话拉链
转到tidyup
:oldexistscontinue如果不存在D:\\ RPS_BACKUP \\ backups_temp \\转到其他tempexists转到tempexistscontinue
:tempexists
如果不存在D:\\ RPS_BACKUP \\ backups_old \\转到其他backupfailed转到tempexistscontinue
:backupfailed
@rd / S / Q D:\\ RPS_BACKUP \\ backups_temp
回声备份没有完成最后一次,备份将重新启动从开始。
暂停
:tempexistscontinueMD 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 \\\\用户3 \\ C \\ * D:\\ RPS_BACKUP \\ backups_temp \\用户3 \\ C / H / E / Z / F / R / I / S / K
IF NOT ERRORLEVEL == 1 GOTO的ErrorHandler
调用子
电话拉链
:整理
重命名D:\\ RPS_BACKUP \\ backups_to_zip备份
暂停
GOTO:EOF:的ErrorHandler
回声xcopyerror code是ERRORLEVEL联系瑞安
暂停


解决方案

使用括号组的各分支:

 是否存在D:\\ RPS_BACKUP \\ backups_to_zip \\(转到zipexist)否则转到zipexistcontinue

在你的情况解析器永远不会看到其他属于如果,因为转到将愉快地接受一切到命令的末尾。您可以使用时,会看到类似的问题回声而不是转到

此外使用括号将允许您直接使用报表,而无需跳跃(虽然我不能够重写code实际使用结构化编程技术;也许是太早或不放贷本身以及阻止结构为code是现在)。

Hi whenever i run the code below it occurs to me I have made a mistake using the if exist lines, as no matter whether the directory exists or not, it acts as if the line was never there... either that or its not reading the else line.


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  

解决方案

Use parentheses to group the individual branches:

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

In your case the parser won't ever see the else belonging to the if because goto will happily accept everything up to the end of the command. You can see a similar issue when using echo instead of goto.

Also using parentheses will allow you to use the statements directly without having to jump around (although I wasn't able to rewrite your code to actually use structured programming techniques; maybe it's too early or it doesn't lend itself well to block structures as the code is right now).

这篇关于如果不存在C:\\目录\\转到别的一个转到b问题,Windows XP中的批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆