Check if a file exists using batch processing
This article will demonstrate how to use a batch script to check if a file exists through sample code.
Check if a file exists using batch script
The general format or syntax of the code to check if a file exists is provided below.
IF EXIST filename.txt (
action if file exists
) ELSE (
action if the file doesn't exist
)
The following example checks if the file simple.txt exists. If the file exists, it is displayed File exists!!!
; if the file does not exist, it displays the message: File missing!!!
.
Sample code:
IF EXIST simple.txt (
echo File exists!!!
) ELSE (
echo File missing!!!
)
Output:
File exists!!!
Keep in mind that the methods discussed here are written using batch scripting and will only work with Windows CMD.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
在 Windows 中使用批处理文件删除文件夹及其内容
Publish Date:2024/03/15 Views:310 Category:编程语言
-
本教程教授如何使用 bat 文件删除文件夹及其内容。
在批处理脚本中使用 IF ELSE 和 GOTO
Publish Date:2024/03/15 Views:113 Category:编程语言
-
本教程将展示我们如何在批处理脚本中组合 IF ELSE 和 GOTO 命令。