This article will demonstrate checking if a file exists or not using a Batch script through an example code.
Check if a File Exists Using a Batch Script
The general format or syntax for 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 below example will check whether the file
simple.txt exists or not. If the file exists, it will show the message
File exists!!!; if the file doesn’t exist, it will show the message:
IF EXIST simple.txt ( echo File exists!!! ) ELSE ( echo File missing!!! )
Remember, the methods discussed here are written using Batch Script and only work in the Windows CMD.
- Rename Part of Filename in Batch Script
- Run Batch File Remotely
- Transfer File to Raspberry Pi Using Batch Script
- Run Multiple Files in Batch Script
- New Line in Batch Script
- Use Batch File to Write to a Text File