Filed under: Features, How-tos
AppleScript: Delete old folders
Continue reading to learn how to create this AppleScript.
Creating the AppleScript
Open Script Editor.app (it can be found in /Applications/AppleScript). When you have the application opened, type (or copy / paste) the entire AppleScript below.
set backupFolder to (choose folder)
tell application "Finder" to set theseFolders to (get folders of backupFolder)
repeat with oneFolder in theseFolders
if (creation date of (info for oneFolder as alias) < (current date) - 30 * days) then
tell application "Finder" to delete oneFolder
end if
end repeat
When you are finished, your script should look similar to the one below.

You can save this script as an application by clicking File > Save As, and choosing "Application" from the "File Format" drop-down box. Type a name and location for your script to be saved and then click the "Save" button.

To run this script, you can double-click on the application that you just created or you can drag it into the dock for easy clicking. When you run the script, you will be presented with a dialog asking you for a folder. Browse to the parent (top-level) folder that contains folders you would like to be searched by date. The script will then find the folders that are older than 30 days and move them to the Mac OS X trash bin.
Additional notes
- Before you remove the files from the trash bin, make sure they are the files you wanted to delete.
- This script only removes folders, so be sure to organize your files within the folders accordingly.
- Be cautious when using this script, as it moves files. TUAW is not responsible for data loss due to incorrect usage of this script.


![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 1)
Picazsoo said 11:55AM on 5-05-2008
Wouldn`t it be safer to just label those folders with a certain colour and later search in Finder for all folders with this label and delete them from there? It is much safer than just moving them straight to trash...
Just my 2 cents...
Reply
Bob said 12:32PM on 5-05-2008
find /path/to/directory -type d -mtime +30 -exec rm -r {} \;
Reply
Jachym Metlicka said 2:40PM on 5-05-2008
Thanks. That's much easier (-:
Murphy Mac said 1:08PM on 5-05-2008
Some day I'd like to see a how-to post somewhere, anywhere, without any comments that say, "Wouldn't it be easier to just..."
Go ahead, suggest ANOTHER way. The more ways the better. But to suggest your way is the best way and every other way is inferior is arrogant. Take a look around. Just, just just just just just. "Why not just....?" "Couldn't you just.....?" So annoying.
Look - JUST write your other method without slamming the way someone JUST took the time to write up. Leave the JUST out.
Reply
Timmargh said 2:34PM on 5-05-2008
Well said Murphy. Well said.
Picazsoo said 2:33PM on 5-05-2008
I am sorry if my comment did sound like that. I am not from an english speaking country so these nuances in language aren't as easy to understand as you might think.
On the other side, I didn't want to be offensive in any way, but you surely wanted to. Actually the reason I posted what I posted was because I hoped someone would suggest the way to do what I wanted. I use Hazel to do this kind of stuff.
Sincerely, Jachym Metlicka
Murphy Mac said 2:59PM on 5-05-2008
Picazsoo - I'll be the first to admit I often forget how many posters don't speak English as their first language. And I'm duly impressed that they can master technology in anything other than their native language.
But the "just" thing pervades every single posting about how to do something. And people who DO speak English as their first language use the phrasing over and over again. I don't know if they realize it's offensive or not. But it is. Simply adding the word "just" devalues the content of the post, if people realize it or not.
I apologize for offending you. I don't know why I ever mention the JUST thing, it's one of those things I need to learn to ignore if I'm going to participate in sites like this.
Reply
Picazsoo said 3:25PM on 5-05-2008
I'll definitely try to avoid this evil "just" from now on (-:
About the tech stuff: Almost all technology I use is in english language. I went to Texas last year as an exchange student, but there are some things one will never learn unless one's a real native speaker.
I'm glad we figured this out.
End of Transmission
Mason said 3:39PM on 5-05-2008
And how would the script look for empty folders?
Reply
Ian said 12:25PM on 5-06-2008
Why not just highlight them all and hit command-delete?
Reply