JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Check if a file exists using batch processing

Author:JIYIK Last Updated:2025/03/20 Views:

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.

Previous: None

Next: None

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.

Article URL:

Related Articles

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial