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
ASKED:
November 10, 2009 10:29 AM
UPDATED:
November 21, 2009 8:38 PM
Although I agree with Jutpro, you may want to check out some of the techniques listed here: Batch Help
Hope this helps!
-Schmidtw
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 doneScript 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 .