Welcome Guest.   Make a donation to an author on the site January 26, 2015, 08:31:08 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2011! Download 30+ custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: IDEA: Specialized folder/file cleanup script  (Read 530 times)
app103
That scary taskbar girl
Global Moderator
*****
Posts: 5,389



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« on: December 22, 2014, 11:24:11 PM »

I have a need for a specialized cleanup script that will delete files & folders according to the following rules:

I have a main folder that contains a number of subfolder with dates as their names, following this format: YYYY-MM-DD

Within those subfolders can be any number of files & folders of unknown naming convention, unknown depth.

What I need is something I can drop into the root folder which when run will check the date named folders and will delete the ones (and whatever may be within them) in which the names correspond to dates older than 2 weeks old, regardless of the actual age of the folder. (it's possible the creation/last modified date may not agree with the folder name)

I need to be able to run it without providing path information at each run, without any confirmation dialogs, without any visible windows, without any prompts or messages about there being nothing fitting those parameters to delete, etc. And it needs to exit when it is done. I do not want to be bothered or interrupted when this runs. (whether you want to send the deleted stuff to recycle bin or not is up to you, but I do not want a dialog asking me if that's what I want to do, every time this is run)

I will be running this as a daily scheduled task to remove content that has been shared via dropbox, to solve support issues more than 2 weeks prior, to ensure the customers will only receive the latest version of the content. I don't want them to be able to download it 3+ weeks later without asking for new links/new content, due to the high probability of there having been revisions and/or corrections to that content.

If there is anything about this that you are unsure about or do not understand, please ask and I will clarify it.
Logged

skwire
Global Moderator
*****
Posts: 4,250



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #1 on: December 23, 2014, 02:14:10 AM »

What I need is something I can drop into the root folder which when run will check the date named folders and will delete the ones (and whatever may be within them) in which the names correspond to dates older than 2 weeks old, regardless of the actual age of the folder. (it's possible the creation/last modified date may not agree with the folder name)

Here's some AHK code to do what you requested.  Save it off as <whatever>.ahk and then run it from the main folder.  It's set to use the recycle bin but I included a commented out line which deletes the folder directly.  I'd test this out first on copy of the folders you're dealing with.  Here you go:

Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  1. Loop, % A_ScriptDir . "\*.*", 2, 0
  2. {
  3.    myNow := A_YYYY . A_MM . A_DD
  4.    myFolder := A_LoopFileName
  5.    StringReplace, myFolder, myFolder, -, , All
  6.  
  7.    EnvSub, myNow, %myFolder%, Days
  8.  
  9.    If ( myNow > 14 )
  10.    {
  11.        ; FileRemoveDir, % A_LoopFileFullPath, 1
  12.    }
  13. }
Logged

app103
That scary taskbar girl
Global Moderator
*****
Posts: 5,389



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #2 on: December 23, 2014, 04:27:35 AM »

It worked beautifully. Thank you!  smiley
Logged

skwire
Global Moderator
*****
Posts: 4,250



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #3 on: December 23, 2014, 08:37:10 AM »

You're very welcome.   smiley
Logged

Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.058s | Server load: 0.03 ]