Download the new Switched app for your iPhone

Skip to Content

Engadget for the iPhone: download the app now
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.
jobs & resumes
TUAW Jobs

Find the Best Candidates & Jobs on the TUAW Jobs Job Board

Find a Job / Post a Job›

Reader Comments (Page 1 of 1)

Tip of the Day

Customize your desktop. While in the Finder, control-click (right-click) and choose 'Show View Options'. A box will appear allowing you to change the size of desktop icons, their spacing, text size and the position of icon labels.

Facebook
Follow us on Twitter!

TUAW [Cafepress] 

Featured Galleries

DNC Macs
Macworld 2008 Keynote
Macworld 2008 Build-up
Google Earth for iPhone
Podcaster
Storyist 2.0
AT&T Navigator Road Test
Bento for iPhone 1.0
Scrabble for iPhone
Tom Bihn Checkpoint Flyer Briefcase
Apple Vanity Plates
Apple booth Macworld 07
WorldVoice Radio
Quickoffice for iPhone 1.1.1
Daylite 3.9 Review
DiscPainter
Mariner Calc for iPhone
2009CupertinoBus
Crash Bandicoot Nitro Kart 3D
MLB.com At Bat 2009
Macworld Expo 2007 show floor

 

Our Writers

Victor Agreda, Jr.

Programming Manager, AOL Tech

RSS Feed

View more Writers

More Apple Analysis

AOL Radio TUAW on Stitcher