本文共 1351 字,大约阅读时间需要 4 分钟。
本文翻译自:
This question already has an answer here: 这个问题在这里已有答案:
I need to run a utility only if a certain file exists. 我只有在存在某个文件时才需要运行实用程序。 How do I do this in Windows batch? 如何在Windows批处理中执行此操作?
参考:
C:\>help if
Performs conditional processing in batch programs. 在批处理程序中执行条件处理。
IF [NOT] ERRORLEVEL number command IF [NOT] ERRORLEVEL数字命令
IF [NOT] string1==string2 command IF [NOT] string1 == string2命令
IF [NOT] EXIST filename command IF [NOT] EXIST filename命令
Try something like the following example, quoted from the output of IF /?
尝试类似下面的例子,引自IF /?
的输出IF /?
on Windows XP: 在Windows XP上:
IF EXIST filename. ( del filename.) ELSE ( echo filename. missing.)
You can also check for a missing file with IF NOT EXIST
. 您还可以使用IF NOT EXIST
检查丢失的文件。
The IF
command is quite powerful. IF
命令非常强大。 The output of IF /?
IF /?
的输出IF /?
will reward careful reading. 会奖励仔细阅读。 For that matter, try the /?
就此而言,试试/?
option on many of the other built-in commands for lots of hidden gems. 许多隐藏宝石的许多其他内置命令的选项。
if exist( rem file exists) else ( rem file doesn't exist)
Or on a single line (if only a single action needs to occur): 或者在一行上(如果只需要执行一个操作):
if exist
for example, this opens notepad on autoexec.bat, if the file exists: 例如,如果文件存在,这将在autoexec.bat上打开记事本:
if exist c:\autoexec.bat notepad c:\autoexec.bat
转载地址:http://yfexb.baihongyu.com/