Windows 10

Batch File To Check If Multiple Files Exist

In this tutorial, we are going to see how to check if multiple files exist in a batch file by using IF EXIST condition. Batch file contains a series of DOS (Disk Operating System) instructions. It allows triggering the execution of commands found in this file.
 

Solution 1: Batch File To Check If Multiple Files Exist
@echo off

if exist "file1.txt" if exist "file2.txt" echo "file1.txt" and "file2.txt" exists!
if not exist "file1.txt" echo "file1.txt" missing
if not exist "file2.txt" echo "file2.txt" missing
 
Output:

 

Solution 2: Batch File To Check If Multiple Files Exist
@echo off

for %%i in ("file1.txt" "file2.txt") do if not exist "%%i" echo %%i missing & goto :EOF
echo "file1.txt" and "file2.txt" exists!
 
Output:

 

Leave a Reply

Your email address will not be published. Required fields are marked *