Quantcast
You are not logged in, click here to log in.
3 Replies Last post: Oct 24, 2007 3:53 AM by Dan Frakes  
Click to view jfredrickson's profile New Member 52 posts since
Apr 7, 2005
Reply

Oct 23, 2007 7:06 PM

Automatically Delete Old Files in Directory

Is it possible to set up a script that executes every day and deletes all the files in a directory older than 1 day?
Reply
Click to view mdawson's profile Old Hand 3,029 posts since
Aug 31, 2004
1. Oct 23, 2007 7:51 PM in response to: jfredrickson
Re: Automatically Delete Old Files in Directory
You can write your own AppleScript to perform the function. You may even be able to create a workflow in Automator that performs the task.


“Cannot run out of time. There is infinite time. You are finite. Zathras is finite. This is wrong tool.” 2.3GHz Power Mac G5/4GB/500GB HDD/OS X 10.4.11/30-inch ACD, 60GB iPod (Color)
Click to view griffman's profile Macworld Editorial 8,113 posts since
Jan 9, 2001
2. Oct 23, 2007 10:38 PM in response to: mdawson
Re: Automatically Delete Old Files in Directory
Unfortunately, Automator (at least as of 10.4; maybe it'll be different in 10.5) lacks any direct ability to either select files based on date or to delete files. However, you can use Automator to run shell scripts, so a solution is possible.

I wrote up what I did in this macosxhints.com hint. It's not necessarily for a Terminal beginner, though it's really not bad. There are also some alternatives in the comments, one of which, Hazel, is a pure GUI solution that helps you create actions for folders to run automatically.

Either the linked hint or Hazel should help you accomplish what you want to do.

-rob.
Click to view Dan Frakes's profile Macworld Editorial 3,348 posts since
Apr 14, 2003
3. Oct 24, 2007 3:53 AM in response to: griffman
Re: Automatically Delete Old Files in Directory
Another solution would be Folder Actions. If you create an AppleScript that checks the date on each file, and deletes those older than a day, you could attach the script to your folder as a Folder Action.


Dan Frakes | Senior Editor, Macworld