我需要运行一个实用程序,只有当某个文件存在。如何在Windows批处理中做到这一点?
当前回答
if exist <insert file name here> (
rem file exists
) else (
rem file doesn't exist
)
或者在一行中(如果只需要发生一个动作):
if exist <insert file name here> <action>
例如,如果autoexec.bat文件存在,这将打开记事本:
if exist c:\autoexec.bat notepad c:\autoexec.bat
其他回答
C:\>help if
在批处理程序中执行条件处理。
IF [NOT] ERRORLEVEL number命令 IF [NOT] string1==string2命令 IF [NOT] EXIST文件名命令
试试下面的例子,引用自IF /?在Windows XP上:
IF EXIST filename.txt ( del filename.txt ) ELSE ( echo filename.txt missing. )
你也可以用IF NOT EXIST检查丢失的文件。
IF命令非常强大。IF /?将奖励仔细阅读。在这个问题上,试试/?选项上的许多其他内置命令为许多隐藏的宝石。
if exist <insert file name here> (
rem file exists
) else (
rem file doesn't exist
)
或者在一行中(如果只需要发生一个动作):
if exist <insert file name here> <action>
例如,如果autoexec.bat文件存在,这将打开记事本:
if exist c:\autoexec.bat notepad c:\autoexec.bat
推荐文章
- 无法在Windows上从/usr/local/ssl/openssl.cnf加载配置信息
- 用Windows任务调度器运行批处理文件
- GIT克隆在windows中跨本地文件系统回购
- 如何运行一个PowerShell脚本而不显示窗口?
- PowerShell:仅为单个命令设置环境变量
- 为什么这个Windows批处理文件只执行第一行,而在命令shell中执行所有三行?
- 如何将文件内容读入批处理文件中的变量?
- 环境变量存储在Windows注册表的哪里?
- 有一个好的Valgrind Windows的替代品吗?
- Windows和Linux上的c++编译:ifdef开关
- 如何验证批处理文件中是否存在一个文件?
- 如何循环通过文件匹配通配符在批处理文件
- 异步运行Windows批处理文件命令
- XAMPP -端口80被PID 4的“无法打开进程”使用!12
- 为什么git在Windows下记不住我的密码