1.

Solve : How to use a batch file to check if the file is empty?

Answer»

For the purpose of error checking I need to know if a file is empty or not. How can I do so using dos/batch commands within my batch script. FIle is called temp.txt

ThanksWhat do you mean "empty"? Do you mean has a size of zero bytes?
To check for 0 byte file from within a batch file, you can do:

Code: [Select]for /f %%a in ('dir filename.txt /B') do if %%~za equ 0 echo %%a is %%~za bytes.
If directly from the COMMAND line, change all the DOUBLE %% to SINGLE %if you mean "empty" is no STRING in that *.txt file,
here is the code to display how much line in that file..

..Untested..
---------------------------------------------
echo off
set /p file=Type Path+Filename :
:up
if not defined array set array=0
for /f "skip=%array%" %%f in ("%file%") do (
    if /i "%%f"==" " (echo file contain(s) %array% line) else (set /a array=array+1)
    goto up
)

the result would display how much line in yourfile...
if contain(s) 0 line, your file is "EMPTY"



Discussion

No Comment Found