使用批处理检查文件是否存在
作者:迹忆客
最近更新:2023/08/14
浏览次数:
本文将通过示例代码演示使用批处理脚本检查文件是否存在。
使用批处理脚本检查文件是否存在
下面提供了检查文件是否存在的代码的一般格式或语法。
IF EXIST filename.txt (
action if file exists
) ELSE (
action if the file doesn't exist
)
下面的示例将检查文件 simple.txt 是否存在。 如果文件存在,会显示 File exists!!!
; 如果文件不存在,则会显示消息:File missing!!!
。
示例代码:
IF EXIST simple.txt (
echo File exists!!!
) ELSE (
echo File missing!!!
)
输出:
File exists!!!
请记住,此处讨论的方法是使用批处理脚本编写的,并且仅适用于 Windows CMD。