Batch file to delete files older than N hours or minutes

Neither of the solutions here worked for me. They are very innovative solutions, and the first one (.net/FileTimeFilerJS.bat [sic]) actually worked once for me. When I tried to call it on another folder, however, it simply crashed. I tried the second one (jscript/FileTimeFilterJs.bat), but it did not successfully delete all files older than one hour.

My solution requires an executable, but I found it was the best solution for me.

I downloaded FindUtils from GnuWin32, and extracted 3 files (you have to download the two zips below): libintl3.dll, libiconv2.dll, and find.exe (combined they are about 1MB in size). I rename find.exe to gnu_find.exe just to avoid the Windows FIND command.

Then, you can run the beautiful GNU command (below command is for all zip files older than 120 minutes in folder specified by environment variable %fldr%):

gnu_find %fldr% -name *[.:]zip -type f -mmin +120 -delete

Instead of *.zip, I use *[.:]zip, because Windows 7+ will expand the *.zip before find can use it.

Find Utils bin

Find Utils deps

Leave a Comment