Page 1 of 1

Renaming file by pulling dates from orig file name

PostPosted: Sat May 09, 2026 11:13 am
by trsands
When I download PDFs of a magazine subscription, the filename is either in the format "January_5,_2026.pdf" or "Monday_4th_May_2026.pdf" I would like to rename the PDFs to the format 2026-01-05 Name of Magazine.pdf" and "2026-05-04 Name of Magazine.pdf" respectively.

I have spent a long time trying to configure a Hazel Rule myself and even a couple of hours using Claude and I can't get past getting a condition to match in preview using "Name" & "matches." I have no real coding experience but have used Hazel for years with lots of success renaming PDFs by pulling data from their contents. My guess that pulling date information that is right in the filename would be easy for me has been proven wrong for my skills.

I am running Hazel 6.1.2 on a MacBook Air M4 running Tahoe 26.4.1

Re: Renaming file by pulling dates from orig file name

PostPosted: Mon May 11, 2026 9:56 am
by Mr_Noodle
Look up "match patterns" in the manual. If you already know how to use those for contents, it is similar when using name. Uses "matches" instead of "contains match". The main difference is that when you use "matches", your pattern has to account for all the characters in the name, not just the part you are interested in.

Re: Renaming file by pulling dates from orig file name

PostPosted: Mon May 11, 2026 10:50 am
by trsands
Mr_Noodle, thank you for this. You made me realize that I was trying to be too fancy by attempting to create a single rule to cover several differently named files. Sadly, this magazine PDFs are named in all different names even though they all included some form of date (Monday_4th_May_2026.pdf, Monday_11th_May_2026.pdf, Monday_23rd_March_2026.pdf, and even December_1,_2025).

I ended up dealing with this by creating six different rules to cover the single & double digit 'th's, the 'rd's, the 'st's, and the straight month_date_year patterns. It didn't take much time at all by using the duplicate function and a simple edit.

The incredible part of this program is that once you set up a rule, everything is so easy going forward.