Delete files based on Size

5 pts.
Tags:
Batch files
Microsoft Windows Server 2003
Is there a way to write a simple Batch file that would allow me to delete all files in a folder with a size of 0KB. I have an application that churns out csv files every two minutes, but quite a few are empty, and I want to get rid of them automatically before archiving the rest.

Software/Hardware used:
win 2003 / XP

Answer Wiki

Thanks. We'll let you know when a new response is added.

If you are looking for all files equal to 0 then the FOR Command will loop through each file. FOR Command example is shown below.

FOR %%F IN (*.*) DO (IF %%~zF LSS 1 DEL %%F)

The above example will go through all files in the current directory, and all files found with a length less than 1 in file size will be delete.

Hope this helps
Jutpro

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Schmidtw
    Although I agree with Jutpro, you may want to check out some of the techniques listed here: Batch Help Hope this helps! -Schmidtw
    11,330 pointsBadges:
    report
  • JenniC
    Here is a script that will delete files in a folder that are smaller than the given number of bytes. The size in bytes and folder path are both arguments to the script.
    # Script DeleteBySize.txt
    var str folder, bytes, filelist, ssize
    var int bytes, filesize
    
    # Get the list of files in $folder.
    lf -n "*" $folder ($ftype=="f") > $filelist
    while ($filelist <> "")
    do
    
        # Get the next file from the list.
        lex "1" filelist > $file
    
        # Get this file's size.
        lf -s $file > $ssize ; set $filesize = makeint(str($ssize))
    
        # Is $filesize smaller than $bytes ?
        if ($filesize <= $bytes)
        do
            # Delete this file.
            system del ("""+$file+""")
        done
        endif
    done
    Script is in biterscripting. Copy and paste the script into file C:/Scripts/DeleteBySize.txt, start biterscrpting, then copy and paste the following command into command area.
    script "C:/Scripts/DeleteBySize.txt" folder("C:/testfolder") bytes(0)
    Above command will delete all files in folder "C:/testfolder" whose file size is 0.
    script "C:/Scripts/DeleteBySize.txt" folder("C:/testfolder") bytes(100)
    will delete all files in folder "C:/testfolder" whose file size is less than or equal to 100. etc. Test the script first before using. The documentation for the lf (list files) command is at http://www.biterscripting.com/helppages/lf.html .
    70 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following