Link to home
Start Free TrialLog in
Avatar of Pradeep chand
Pradeep chand

asked on

Batch script to check for file size and delete/keep

I am running a batch script that checks for error files in a specific folder every 60 seconds.This script deletes any error file with size 0 kb(empty file).
If the file size is greater than 0 kb it should exit the loop.

I am unable to exit the loop if  the file size is greater than 0 kb. Please advise.
For your reference the script I have implemented is as follows.

:Loop
FOR %%F IN (C:\errorfolder\error*) DO (
IF %%~zF LSS 1 DEL %%F
) 

timeout /t 60 /nobreak >nul 2>&1

goto :Loop

Open in new window


Thanks.
Avatar of Bill Prew
Bill Prew

Which loop are you trying to exit?  You want to process all files in the FOR loop right, so that you delete the 0 size ones, and leave the rest.  So I don't think you want to exit that loop.

If you mean the GOTO loop named :LOOP, then under what condition do you want to exit that?

~bp
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pradeep chand

ASKER

Thanks oBdA. This works great!