topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Monday March 18, 2024, 9:16 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

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

hurricanedavid

  • Participant
  • Joined in 2005
  • *
  • default avatar
  • Posts: 17
    • View Profile
    • Donate to Member
DONE: Folder Cleaner
« on: October 31, 2005, 02:59 PM »
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.).
  • Delete files that do not have a certain string in their name.
  • Delete files whose names do not match a certain regular expression.
  • Delete text files that do not have a certain string in their content.
  • Delete text files whose content does not match a certain regular expression.

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.

Edvard

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 3,017
    • View Profile
    • Donate to Member
Re: IDEA: Folder Cleaner
« Reply #1 on: November 01, 2005, 11:58 AM »
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:
msgbox,52,Clean Folder,Are you sure you want to clean Temp folder?
if msgbox,no
exit
loop,z:\Temp\Dir\*.*,0,1
{
filerecycle,%a_loopfilefullpath%
}

msgbox,0,Clean Folder,Temp Directory clean!
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.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Folder Cleaner
« Reply #2 on: November 01, 2005, 01:10 PM »
i love this idea for a reall flexible clearning system -
personally i'd also love to see it so you could right click on a directory and apply the rules,.

and most of all i'd like to get a report in the form of a checklist before it actually does anything, so i could unselect stuff i didn't want deleted.

i've seen some related programs for cleaning temporary program files - if you find a good solution let us know.

definitely sounds like a nice utility for someone looking for something to program, though might be a bit bigger than a coding snack, at least what i'm thinking about.

go197

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 12
    • View Profile
    • Donate to Member
Re: DONE: Folder Cleaner
« Reply #3 on: December 28, 2006, 09:43 AM »
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.