文件始终存在批处理文件 [英] File Always Exist Batch file
问题描述
我有一批检查文件是否存在.请参见下面的代码.
I have a batch which check the existence of a file. Please see code below..
@ECHO OFF
REM Clear screen before executing other commands
CLS
SET WebConfig=C:\inetpub\wwwroot\ABC\Web.Config
SET CodeLocation=C:\inetpub\wwwroot\ABC\*.*
IF NOT EXIST %WebConfig% GOTO WebError
:WebError
ECHO Web.Config File doesn't Exist...
pause
GOTO:EOF
ECHO Working..
执行批处理文件时,我始终会收到一个不存在的错误文件.即使该文件存在于define文件夹中..
When executing the batch file, i always receive an error file doesn't exist.. Even though the file exist in the define folder..
你们能帮助我吗?希望很快能收到您的来信.
Can you guys help me..? Hope to hear from you soon..
谢谢
Nestea
推荐答案
仔细查看此部分代码:
IF NOT EXIST %WebConfig% GOTO WebError
:WebError
现在文件存在时会发生什么?不要回答,这很夸张:-)
Now what happens when the file exists? Don't answer, it's rhetorical :-)
它会跳到下一行,即等待错误消息部分.
It drops through to the next line which is, wait for it, the error message section.
请尝试执行此操作,当if
语句不跳转时,它将跳过错误消息部分:
Try this instead, it skips over the error message section when the if
statement doesn't jump:
if not exist %WebConfig% goto WebError
goto WebOkay
:WebError
echo Web.Config File doesn't exist.
pause
goto :EOF
:WebOkay
echo Working.
也可以进一步简化为:
if exist %WebConfig% goto WebOkay
echo Web.Config File doesn't exist.
pause
goto :EOF
:WebOkay
echo Working.
这篇关于文件始终存在批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!