Page 1 of 1

Delete older file based on date in file name

PostPosted: 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?

Re: Delete older file based on date in file name

PostPosted: Mon Aug 29, 2016 1:57 pm
by Mr_Noodle
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.

Re: Delete older file based on date in file name

PostPosted: Sat Sep 10, 2016 6:17 pm
by mcginnie
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.