Skip to Content

Are you prepared for Wrath of the Lich King? WoW Insider has you covered!
AOL Tech

Filed under: Features, How-tos

AppleScript: Delete old folders

If you work like I do, then you have a hierarchy of folders contained in a single folder that allows you to manage project files, notes, etc. Well, when it comes time to chunk those old files, normally you have to manually go through and remove them; this task can become daunting if you have multiple project folders. I am going to show you an easier way. In this how-to, we'll cover how to create an AppleScript that will allow you to remove folders that are older than 30 days.

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.

Saving the script
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.

Running the script
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.

Recent Posts

Relevant Posts

Reader Comments (Page 1 of 1)

Tip of the Day

Need a quick way to rename a file or folder in Finder? Instead of click-wait-click, just click once and hit Return (Enter). The name will highlight and be ready to edit.


Follow us on Twitter!

Sponsored Links

Featured Galleries

DNC Macs
Macworld 2008 Keynote
Macworld 2008 Build-up
Podcaster
Apple Vanity Plates
Apple booth Macworld 07
DiscPainter
Crash Bandicoot Nitro Kart 3D
Macworld Expo 2007 show floor
Apple Texas Hold 'Em
The Macworld Faithful in Line
iPhone First Look
Facebook 2 for iPhone
Ten Fun and Free iPhone apps
Take a stroll down memory lane
First Look: SousChef for Mac
First Look: Grocery iQ for iPhone
Pixelmator 1.3
Earthscape
MacTablet Faux Gallery
Watch It Change

 

More Apple Analysis