-2

My code is:

@ECHO OFF

IF EXIST D:\TestCMD\1.TXT GOTO 1

ELSE

ECHO NOT EXISTED FILE 1.TXT

:1

ECHO EXISTED 1.TXT

--> It work nomally but when i changed "1.txt" to "2.txt" --> It doesn't work and error: "else is not recognized as an internal or external command, operable program or batch file."

@ECHO OFF

IF EXIST D:\TestCMD\2.TXT GOTO 1

ELSE

ECHO NOT EXISTED FILE 1.TXT

:1

ECHO EXISTED 1.TXT

--> What's happen?

SachaDee
  • 9,245
  • 3
  • 23
  • 33
  • 1
    Maybe [this](http://stackoverflow.com/a/25073859/2861476) can help – MC ND Sep 15 '14 at 10:25
  • Or reading `if /?` could also help – jeb Sep 15 '14 at 10:28
  • 1
    Possible duplicate of ['else' is not recognized as an internal or external command, operable program or batch file](http://stackoverflow.com/questions/12365374/else-is-not-recognized-as-an-internal-or-external-command-operable-program-or) –  Feb 03 '17 at 04:04

1 Answers1

1

This syntax should help you:

@ECHO OFF
IF EXIST "D:\TestCMD\1.TXT" (
      ECHO EXISTED 1.TXT
  ) ELSE (
      ECHO NOT EXISTED FILE 1.TXT
)
pause
foxidrive
  • 40,353
  • 10
  • 53
  • 68