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..
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..
Thanks,
Nestea
Look closely at this section of code:
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.
Try this instead, it skips over the error message section when the
ifstatement doesn’t jump:It can also be further simplified to: