开发者

Batch command getting error

I wrote a simple batch file which check开发者_Python百科s 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.


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.


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜