Page 1 of 1

Delete single file if it was last modified over 5 hours ago

PostPosted: Mon Apr 04, 2011 3:13 am
by ryansebiz
Hi Mr_Noodle & Hazel Community,

I'm trying to create a rule that deletes a specific file ("creaturecache.wdb") if it was last modified over 5 hours ago. There are other files in this folder that I don't want deleted.

Image

The weird thing is that when I preview this rule it matches several files:

Image

Any ideas on how to periodically delete this file are greatly appreciated!

Re: Delete single file every day at 4am

PostPosted: Mon Apr 04, 2011 4:12 pm
by dhy8386
First, that second screen actually shows Hazel is matching 0 rules (the column on he right). If you run a rule on Folder A, that preview button will show you everything in Folder A and what rules match the files/directories in that folder. So if for example, the date last modified condition was true (which it does not appear to be in this case), then in the second screen shot in column 2 under Rule Matched, you would see a "Clear NPCscan cache" for the row creaturecache.wdb.

To the short answer is without a script, Hazel can not act at a specific time in the day. However, you may be able to accomplish the same thing if I can understand a little bit more about your process. Why at 4am everyday? Do they get created at a specific time every day always? Does it have to be immediate or is this just housekeeping?

Re: Delete single file every day at 4am

PostPosted: Mon Apr 04, 2011 4:37 pm
by ryansebiz
@dhy8386 thanks for the reply. It doesn't have to be at 4am; it could be if the file was last modified about 5 hours ago (or longer). Either is fine. It's just housekeeping.

Re: Delete single file every day at 4am

PostPosted: Mon Apr 04, 2011 5:38 pm
by sjk
dhy8386 wrote:Hazel can not act at a specific time in the day.

Which is why cron or launchd can be more suitable for scheduling time-specific tasks.

Re: Delete single file every day at 4am

PostPosted: Mon Apr 04, 2011 5:52 pm
by ryansebiz


File modified over 5 hours ago is fine - doesn't have to be time of day. I'd like to use Hazel for this.

Re: Delete single file if it was last modified over 5 hours

PostPosted: Tue Apr 05, 2011 3:03 pm
by Mr_Noodle
The rule looks correct. Maybe the date modified is not what you think it is? Select the file in Finder and do "Get Info" and make sure the date modified is actually not in the last 5 hours.

Re: Delete single file if it was last modified over 5 hours

PostPosted: Tue Apr 05, 2011 9:16 pm
by dhy8386
as a test, since your rule looks right, try this:

Name Contains creaturecache
Extension is wdb

See if that works (assuming you are sure the modified period is over 5 hours).

Re: Delete single file if it was last modified over 5 hours

PostPosted: Tue Apr 05, 2011 10:09 pm
by Mr_Noodle
Yes, dhy8386 is correct. I overlooked the first part of the rule where you match the name. The name does not include the extension. You should do either as he mentioned or use the "Full Name" attribute.