Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • May 02, 2016, 06:15:36 PM
  • Proudly celebrating 10 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: IDEA: Specialized folder/file cleanup script  (Read 1772 times)

app103

  • That scary taskbar girl
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 5,624
    • View Profile
    • App's Apps
    • Donate to Member
IDEA: Specialized folder/file cleanup script
« 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.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,535
    • View Profile
    • Donate to Member
Re: IDEA: Specialized folder/file cleanup script
« 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:

Code: Autohotkey [Select]
  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. }

app103

  • That scary taskbar girl
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 5,624
    • View Profile
    • App's Apps
    • Donate to Member
Re: IDEA: Specialized folder/file cleanup script
« Reply #2 on: December 23, 2014, 04:27:35 AM »
It worked beautifully. Thank you!  :)

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,535
    • View Profile
    • Donate to Member
Re: IDEA: Specialized folder/file cleanup script
« Reply #3 on: December 23, 2014, 08:37:10 AM »
You're very welcome.   :)