Macworld Forums: Automatically Delete Old Files in Directory - Macworld Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Automatically Delete Old Files in Directory

#1 User is offline   jfredrickson Icon

  • Member
  • PipPip
  • Group: Members
  • Posts: 52
  • Joined: 07-April 05

Posted 23 October 2007 - 06:06 PM

Is it possible to set up a script that executes every day and deletes all the files in a directory older than 1 day?
0

#2 User is offline   mdawson Icon

  • Veteran
  • PipPipPip
  • Group: Members
  • Posts: 3,768
  • Joined: 31-August 04

Posted 23 October 2007 - 06:51 PM

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.
0

#3 User is offline   griffman Icon

  • Advanced Member
  • Icon
  • Group: Moderators
  • Posts: 8,596
  • Joined: 09-January 01

Posted 23 October 2007 - 09:38 PM

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.

#4 User is offline   Dan Frakes Icon

  • Advanced Member
  • Icon
  • Group: Moderators
  • Posts: 3,756
  • Joined: 14-April 03

Posted 24 October 2007 - 02:53 AM

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.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users