alice7
alice7

Reputation: 3880

Batch command getting error

I wrote a simple batch file which checks whether the c drive path exists then execute the exe in that path else try the d drive path and execute it.

IF EXIST c:\program files\x goto a 

ELSE goto b


:a
cd c:\program files\x

executable.exe  c:\temp\col.zip 


:b
cd d:\program files\x

executable.exe  c:\temp\col.zip

Im getting this error:

----Error Ouput-- 'ELSE' is not recognized as an internal or external command, operable program or batch file. The system cannot find the path specified. 'executable.exe' is not recognized as an internal or external command, operable program or batch file. 'dellsysteminfo.exe' is not recognized as an internal or external command, operable program or batch file.

I don't know why.

Upvotes: 1

Views: 9207

Answers (3)

John Knoeller
John Knoeller

Reputation: 34218

Yep, theres no multiline if/else, just do this

IF EXIST c:\program files\x goto a
goto b

:a 
cd c:\program files\x
executable.exe c:\temp\col.zip
rem don't you want a goto here??


:b 
cd d:\program files\x
executable.exe c:\temp\col.zip

Upvotes: 0

JRL
JRL

Reputation: 78033

The ELSE must be on the same line. Change it to:

IF EXIST c:\program files\x (
  goto a
) ELSE (
  goto b
)

See this tutorial for more details, or refer to this Microsoft documentation.

Upvotes: 10

Chad Birch
Chad Birch

Reputation: 74658

The error message is pretty self-explanatory, there's no such thing as ELSE in batch files. However, since it's a GOTO, it's entirely unnecessary.

IF EXIST c:\program files\x goto a

goto b

If it makes it past the first line, it's inherently an else.

As for the other errors, they're related to not finding the files you're trying to execute. Batch files are case-sensitive, so you need to fix the capitalization of the file/folder names to match the actual system.

Upvotes: 0

Related Questions