Author
Topic: DONE: Folder Cleaner (Read 6113 times)

Example #1: I have a folder in which is put one copy of every screenshot I take. I would like to keep them around for a certain time, then delete them.

Example #2: Or perhaps I just want to have 14 files in there maximum. And when more than 14 are found, the oldest ones are deleted to keep the count to 15 or less.

The program I am suggesting would store cleanup settings for each folder the user wants "cleaned" periodically. It would also perform those cleaning tasks when initiated (like at startup).

Possible Cleaning Methods...

Delete files older than a certain number of days (or hours, etc.) old.

Delete oldest files when the maximum file count for that folder is reached or exceeded.

Delete oldest files when the maximum total file size for that folder is reached or exceeded (i.e. when all files' size adds to more than specified amount, oldest are deleted until max is reached or passed.).

There are probably more cleaning methods out there, but these might be the most common. The first three were really the ones that spawned this idea. The others just came as I was thinking on how to make it better.

And perhaps you could put a certain filter on the first three options. Like, skip all .html files, but clean all jpg files.

I know windows cleanup is nice, but as far as I can tell, it just deletes them all, rather than keeping the most recent, etc.

If you'd like to try your own hand at scripting, I have an Autohotkey script (can't swing a dead cat around DonationCoder without hitting one...) that might get you started. It's quite a bare-bones script I use to clean the temp folders here at work that basically sends to the recycle bin all files inside all folders in z:\temp\dir. For walk-in customers we use a directory of temp folders labeled temp1-temp9 in the temp dir and it was such a pain to go in and clean out every one at the end of the day I did this:

This probably isn't exactly what you need, but take a look at the "File Loop" entry in the AHK help file and there you'll find that you can sequentially select files for action (delete,recycle,rename, whatever) based on their creation or modified date or anything, really. And settings can be stored in a standard .ini file and subsequently read using the IniWrite/Iniread functions or even store values in the Registry with RegWrite/RegRead like the Pros do! Check it out.

I was looking for something like this and found this thread. I'm looking for something I can just set a rule on a folder to delete files older than x days. Maybe it could run as a scheduled task every night to make the coding easier.