|
Answer» Ok, bit of an unusual one here. I am not great at writing batch scripts myself but can normally tweak EXISTING ones as required.
I have found lots of scripts to delete blank files found in a folder but I need SOMETHING a bit different. I have a folder full of files that are updated daily, if there is a blank file (0kb) in the folder then it means that file has gone wrong.
What I'm after is a script that can check all files on the folder and e-mail me with a list of any blank ones - they are all named differently.
Is anyone able to help as I'm stuck? Thanks AntonI would test for file size INSTEAD of trying to read in the contents to look to see if it is empty, and search for files less than or equal to 1KB in size maybe. Trying to think of how to code this up though.... hmmm This could be done, using VBScript, or something similar.
I don't know if it can be done using DOS batch commands. Code: [Select]FOR /F "delims=" %%A IN ('dir /b') DO ( IF %%~zA EQU 0 echo File %%A is zero bytes in size. )
IF %%A is the filename the ~z modifier gives the file size in bytes
Trout's code works great except it lists directories as empty files. Need /a-d
Code: [Select]@echo off
FOR /F "delims=" %%A IN ('dir /a-d /b') DO ( IF %%~zA EQU 0 echo File %%A is zero bytes in size. ) Output:
C:\>zzero.bat File 3 is zero bytes in size. File AUTOEXEC.BAT is zero bytes in size. File CONFIG.SYS is zero bytes in size. File findstr is zero bytes in size. File hiberfil.sys is zero bytes in size. File IO.SYS is zero bytes in size. File Keeptime.bat is zero bytes in size. File line.bat is zero bytes in size. File Mon is zero bytes in size. File MSDOS.SYS is zero bytes in size. File pagefile.sys is zero bytes in size. File particular.bat is zero bytes in size. File SET is zero bytes in size. File xinc.bat is zero bytes in size. File xvar.txt is zero bytes in size. C:\>type keeptime.bat
C:\>Quote from: billrich on July 24, 2009, 01:59:06 AM Trout's code works great except it lists directories as empty files. Need /a-d Good CATCH, billrich!
|