Delete older file based on date in file name

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Delete older file based on date in file name Thu Aug 25, 2016 7:24 pm • by mcginnie
I am trying to figure out if I can do the following:

After Hazel moves a file (with a name such as 2016-08-25-phone bill) to a specific folder, search that folder for the file with an earlier date in the name (2016-07-25-phone bill) and delete the earlier file.

I can't figure out how to get it to search for a file name with that string, and compare it to the earlier one. I guess I could get it to search the content, but I still don't know how to tell it to delete based on a "date before." I don't want to rely on a simple rule that deletes files after a month, because I may not scan and save the next bill right when I receive it.

I'm guessing I may need to combine a Hazel rule with an Apple Script or Automator?
mcginnie
 
Posts: 6
Joined: Thu Aug 25, 2016 7:11 pm

Why not just use the date added on the file instead of parsing the date? You can use "is not among the X most recent" to keep the X most recent files around while deleting the rest.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks for the reply! That worked (after some trial and error - a learning process). I see now that I was trying to do too much in one rule.

I appreciate the help.
mcginnie
 
Posts: 6
Joined: Thu Aug 25, 2016 7:11 pm


Return to Support