如何从批处理文件中检查文件是否存在
仅当某个文件存在时我才需要运行实用程序。如何在 Windows 批处理中执行此操作?
I need to run a utility only if a certain file exists. How do I do this in Windows batch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
或者在一行上(如果只需要执行一个操作):
例如,如果文件存在,这将在 autoexec.bat 上打开记事本:
Or on a single line (if only a single action needs to occur):
for example, this opens notepad on autoexec.bat, if the file exists:
在批处理程序中执行条件处理。
Performs conditional processing in batch programs.
请尝试类似下面的示例(引用自 Windows XP 上
IF /?
的输出):您还可以使用
IF NOT EXIST
检查丢失的文件。IF
命令非常强大。IF /?
的输出将有助于仔细阅读。就此而言,请在许多其他内置命令上尝试使用/?
选项,以获得许多隐藏的宝石。Try something like the following example, quoted from the output of
IF /?
on Windows XP:You can also check for a missing file with
IF NOT EXIST
.The
IF
command is quite powerful. The output ofIF /?
will reward careful reading. For that matter, try the/?
option on many of the other built-in commands for lots of hidden gems.