Skip to main content
Jan 05, 2012

Recently during a project we have worked on in Inforbiro we have needed to check if some files are empty or not using batch on Windows environment. We have thought that it would be extremely simple (at the end it was) but research taken time :)

So we created a script for our needs and share the code with you hoping that it would be useful.

Copy the code into a file, save it with .bat extension and run it passing a file for checking as a parameter. For example:

C:\check_empty.bat C:\file_for_checking.txt

:: Created by MitraX (www.inforbiro.com) 
:: Batch checks whether a file is empty or not
@echo off 
if "%~z1" == "" ( 
    echo File doesnt exist. 
) else if "%~z1" == "0" ( 
    echo File is empty
) else ( 
    echo File is not empty
)