Q:

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.. 

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 

A:

Look closely at this section of code:
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.
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.

It can also be further simplified to:
    if exist %WebConfig% goto WebOkay
    echo Web.Config File doesn't exist.
    pause
    goto :EOF
:WebOkay
    echo Working.

