Help with Hazel to read file names


I am very new to Hazel rules and I am trying to sort out my old receipts by the date. Since they date back in many years from now and I don’t have OCR to help me with this, I thought that I could scan the file I want to digitalize and add the date to its name manually. Then the Hazel would read what the date is in its name and make sub folders from that date. Example: file name: 20201018 grocery store receipt. Hazel would make sub folders 2020 → 10 → 18 and move that file into there.

I am now asking some help how to make it do things according to the file name. Be cause I can’t get right rules to my mind how this could be done. I am not asking anyone to do it all for me, but since I am not an expert in this I need some help with this.

Also if you think this is completely stupid way and there is much more efficient way to do it then please tell me, so I don’t waste my time trying to figure this out.

I am not familiar with OCR technology and how that works, but I guess its more complicated to find out the right date from the files in that way. So I thought the fastest way to get this work done is enter the date manually into the file name before sending it into folder that is watched by Hazel.

You can do something like this:

Download here then import.

1 Like

Is there some more convenient way to do this? I want it to recognize files that are named like “20201214 word1 word2 word3” or with only two or one word after date. So I decided to make three exact rules except they recognize different amount of word after the date in the file name. It works like this too, but is there a way to put them all into one rule?

And then I need to ask how did you manage to create that yyyymmdd part into the subfolder section? I tried to make it myself, but I couldn’t get it done :thinking:

Would you settle for using "Name starts with" as your match? Or just change the match of everything after the date to match anything rather than varying between 1 and 3 words. That might be easier to wrap your head around.

“Name starts with” doesn’t work since I don’t know how to make the token for date in there, but the match to everything after the date is actually working like I was asking to.

Then I tried to add renaming pattern into the end of the rule so it would rename the file with no date in front of the name after its in its final folder destination, but it doesn’t do anything to file name and I don’t exactly know why. I think its because the file must have the date first so it matches the conditions and if the rule tries to change the name to something that doesn’t match the conditions in the first place its impossible to do.