windows IF Exist Do 语句(批处理文件)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5997799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:51:03  来源:igfitidea点击:

IF Exist Do Statement (Batch File)

windowsbatch-file

提问by James

Please could someone give me an example in batch of something like:

请有人给我一个批处理的例子,例如:

IF test.txt EXISTS DO start test.txt

如果 test.txt 存在,请启动 test.txt

回答by Cat Plus Plus

You can do if /?or help if, you know.

你可以做if /?help if,你知道。

if exists file command

For multiple commands (or when using else), enclose them with parentheses, i.e.

对于多个命令(或使用时else),用括号将它们括起来,即

if exists file (
    command1
    command2
)

回答by cpx

Example -

例子 -

IF EXIST test.txt start test.txt