# Batch Files - Check if empty



## dah0002

Hi,
I have made a batch file (batchMain) that successively calls 4 other batch files. the fourth of which (batch4) may at times be empty. I have sheduled batch main to run daily and it outputs to a text file whether each of batch files 1 to 4 completed successfully. The problem is that whenever batch4 is empty it outputs an error. Is it possible to check whether batch 4 is empty before deciding to call it?

Any help would be much appreciated.

Cheers,
Sam


----------



## Squashman

I am kind of confused on why it would be empty. Why not just delete or rename the file and then do an IF EXISTS.


----------



## Squashman

http://www.computing.net/windows95/wwwboard/forum/167338.html



Code:


@echo off
for %%R in (filename.bat) do if %%~zR equ 0 goto :eof
:: DONE


----------



## dah0002

One of the batches before batch4 runs a script that creates batch4 regardless of whether it needs it (it compares 2 lists of nodes and puts any that need adding to the second list into batch 4, it's run daily but there aren't usually new nodes so batch 4 may be empty). Else I would have deleted it and used if exists. I figured messing with batch files was easier than messing with the .pl

Big thanks for the help!


----------



## Squashman

Well, I can do it alot easier in a Linux Shell script then with a batch file, but the above example does the job.


----------



## blaqDeaph

Squashman said:


> Well, I can do it alot easier in a Linux Shell script then with a batch file, but the above example does the job.


Thats the problem remember? Thats the difference between Windows and Linux. Linux is native on the CLI with GUI as the addon. Windows is native on the GUI (or so they claim) and uses the CLI for admin purposes.


----------



## JohnWill

Why not just let the empty batch job run? It'll do nothing, but it won't hurt anything.


----------



## Squashman

I think this issue was resolved with the links I posted above.


----------



## JohnWill

I'm still curious as to why there ever was an issue.


----------

