I would like Hazel to sort files into existing subfolders based on the file’s name. For example, Hazel monitors a folder called Top Folder. Inside of Top Folder is Subfolder 1 and Subfolder 2. If I put a file named File 1 into the Top Folder, I want Hazel to move the file into Subfolder 1 because the number 1 matches that subfolder. Is there a way to do this? Many thanks!
Sure, this would be fairly easy. It might get tricker if you have 10 sub-folders and you want to match the ‘1’ to ‘1’ and not ‘10’ but even then it would be “do-able”.
Is the number in the filename always at the end of the filename? So
File 1 Report.rtf
Also, will there always be a space before the number?
Hazel has options for if the file name contains something or ends with something. Which one I would use depends on how consistently the files are named and how many subfolders you are dealing with.
@Tjluoma has the same approach I would take. If you’re familiar enough with Hazel, I’d “tokenize” the matched ending numeral (the “1”) in your example. Do this by choosing “matches” as the rule criteria, and then “Custom Text” for the matched element (and specifying it as a number in the Custom Text setup):
“File [Custom Text Token]”
That would match the “File “ portion and then tokenize the ending digit(s).
That way, you can set the action as Sort Into Subfolder, using the pattern “Subfolder [Custom Text Token]”.
That would have the added benefit of creating the Subfolder if it didn’t exist. And it ensures the subfolder names are exactly that of the ending filename digit.
Thanks for the help! In the real world, the folders and the files always start with a five digit code (e.g. 12345 File should go into 12345 Folder), but there is always a space between the number and the word. I think that your method should be revisable though. I’ll let you know if it works!
Thanks for the tip! I’ll let you know if it works!
You all are the best! I’m not sure how to write it out, but I hope the screen shot helps. I match anything with a five digit code, then sort into a subfolder with matching text (the same five digit code, by magic I guess). I very much appreciate the point in the right direction!
UPDATE 1: Spoke too soon! What I have picks up all files that start with a 5 digit code (I added that it has to be a file, not a folder), but it does not always sort into the correct subfolder. I’m having trouble figuring out how to tell Hazel to sort into an existing subfolder with the exact same starting 5 digit code.
UPDATE 2: Got it working. I don’t know why this works, but it works.
To get the file:
- Kind is Document
- Name matches Custom Text set to a five digit number followed by Anything.
To sort the file:
- Sort into subfolder with pattern Custom Text followed by anything.
I put an updated picture below. Thank you again for the help!
I would call this “bucketing” or “sifting”. Pet peeve: Use of the word “sort” for anything other than ordering items. Unless, of course, we deploy “sorted” as short for "sorted out”, as UK English would have it.
However, generalising this technique would be a very nice thing.
Have you seen the Lists & Tables feature in the recently released Hazel 5? Seems as if what you are describing fits in well.
Glad it’s working now. I should have pointed out in my example that the spaces I put into my examples should have been included literally.
I see in your screen shot they are not included.
To include a space, just literally type a space character in the rule criteria fields, in-between each blue “lozenge”. Specifically, between “Five Digit Number” and the “…” blue lozenges.
That should help to prevent further false positives. The closer the match pattern is to the exact filename structure, the better. If the 5-digit pattern follows any pattern (like being a date, or always starts with the same two digits, or something like that), including that into your rule criteria will make this more robust.
Same for the “…” (“anything”) criteria. If it follows any patterns, incorporate those in the rule.