博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何检查批处理文件中是否存在文件[重复]
阅读量:2380 次
发布时间:2019-05-10

本文共 1351 字,大约阅读时间需要 4 分钟。

本文翻译自:

This question already has an answer here: 这个问题在这里已有答案:

  • 3 answers 3个答案

I need to run a utility only if a certain file exists. 我只有在存在某个文件时才需要运行实用程序。 How do I do this in Windows batch? 如何在Windows批处理中执行此操作?


#1楼

参考:


#2楼

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命令


#3楼

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. 许多隐藏宝石的许多其他内置命令的选项。


#4楼

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/

你可能感兴趣的文章
关于桌面软件的开发语言和开发框架的思考
查看>>
打开word2010每次都要配置进度的解决办法
查看>>
使用动态数组结构的一个好处
查看>>
移动铁通宽带上网设置教程
查看>>
怎样的提问才是有效的提问
查看>>
山城之旅
查看>>
有关在对话框上创建视图上的再探索
查看>>
读史可以明智
查看>>
VC常用代码之创建进程
查看>>
如何保住一个人一生的劳动果实
查看>>
并行处理系统测试正式启动
查看>>
bcg库使用心得两则
查看>>
我和CSDN的那些事
查看>>
阅读分几种
查看>>
cannot connect to host的解决办法
查看>>
怎样在C++工程中集成C#窗口
查看>>
语言就是建立自己和世界的联系
查看>>
Cleanup failed to process the following paths错误的解决
查看>>
易康(eCognition)的野心
查看>>
从同事的一个提问想到的学习途径
查看>>