IF EXIST: The syntax of the command is incorrect.

时间:2022-04-15 02:39:32

Batch 脚本中使用 IF EXIST 语句时,总是提示

The syntax of the command is incorrect.

原始 bat 脚本如下:

ECHO OFF
SET project="C:\Temp" IF EXIST %project%\build.log(
ECHO File found
)ELSE(
ECHO File missing
)

原因是遗漏了起关键作用的 空格

ECHO OFF
SET project="C:\Temp" REM There must be a space placed before the parenthesis (
REM 圆括号 ( 前要留有一个空格。
IF EXIST %project%\build.log (
ECHO File found
) ELSE (
ECHO File missing
)