开发者

Windows bat script: how to judge if a file exists? [duplicate]

This question already has answers here: How 开发者_C百科to verify if a file exists in a batch file? (3 answers) Closed 8 years ago.

Pseudo code:

if file exists:
do
    xxxx
done
else:
do
    xxxx
done


You can use exist:

if exist somefile.dat echo It exists

Depending on the "dialect", you can use else statements. At the lowest level, though, some rather ugly logic like this works:

if exist somefile.dat goto fileexists
echo file does not exist
goto alldone

:fileexists
echo file exists

:alldone


Syntax is as follows:

IF [NOT] EXIST filename command

You can use the [NOT] option to execute code if a file doesn't exist as opposed to if the file does exist, however this can be done as an ELSE staement in a standard IF EXIST statement.

IF EXIST stuff.txt (
  ECHO It exists
) ELSE (
  ECHO It doesn't exist
)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜