ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

IDEA: Specialized folder/file cleanup script

(1/1)

app103:
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:
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)-app103 (December 22, 2014, 11:24 PM)
--- End quote ---

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 ---Loop, % A_ScriptDir . "\*.*", 2, 0{    myNow := A_YYYY . A_MM . A_DD    myFolder := A_LoopFileName    StringReplace, myFolder, myFolder, -, , All        EnvSub, myNow, %myFolder%, Days        If ( myNow > 14 )    {        FileRecycle, % A_LoopFileFullPath        ; FileRemoveDir, % A_LoopFileFullPath, 1    }}

app103:
It worked beautifully. Thank you!  :)

skwire:
You're very welcome.   :)

Navigation

[0] Message Index

Go to full version