Automatically move and rename file using folder name

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

I apologise if this is already a topic but I'm wondering if there is a way to setup a rule that will automatically file a PDF document and rename PDF with the same name as the sub-folder name when the files are added to the parent folder.

For example, I have 10 pre-made folders all with individual SKU names and the PDF file has the beginning of the folder name minus the name at the end. See screenshot for more context.

https://i.imgur.com/KPA2xxP.png
Viboxing
 
Posts: 7
Joined: Fri Aug 25, 2023 3:56 am

You can use "Sort into subfolder", using the file's name attribute as the pattern followed by the "..." attribute. That makes it so it will file it into the first folder it finds that matches the file's name followed by whatever afterwards.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks so much for the quick reply. I've managed to get it to file automatically into subfolders but it's not adding the '-Robinia' at the end of the PDF file name to match the folder name.

I basically want the file to take on the same name as the folder once its copied in.

I apologise if I've missed something but below is the rule I've set:

https://i.imgur.com/ZdMOIUV.png

https://i.imgur.com/l1od2g7.png
Viboxing
 
Posts: 7
Joined: Fri Aug 25, 2023 3:56 am

Sorry, missed that part. That's a bit more involved. Look up "match patterns" in the manual. There are several ways to do this but I'd suggest something like the following:

- Create a nested condition (look that up in the manual) to match against any file in the same folder as the file.
- Under that nested condition, match a folder with a pattern like "(anything)-(• suffix)" where (•suffix) is a custom attribute you create to match the name at the end.
- You can then rename the file using (name)-(•suffix), where (name) would be the original name of the file and (•suffix) will be the end of the folder name you matched earlier.
- The sort into subfolder pattern could be the same pattern as either before or the one you used to rename the file, since they are the same.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks again for helping me! I've followed all of your instructions (I think) but I think somethings still missing as the rule isn't performing any actions now? Apologies if I'm not getting it.
Below is the setup:

Image

Image


Note: I would have multiple unique suffixes so setting one for each folder doesn't make sense if that's what you're suggesting? (see below)

Image
Viboxing
 
Posts: 7
Joined: Fri Aug 25, 2023 3:56 am

In your nested condition, you might want to specify Kind is Folder so that it doesn't match the file itself.

From there, go through the troubleshooting guide here: https://www.noodlesoft.com/kb/hazel-tro ... ing-guide/
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

After LOTSSSSS of trial and error and lots of folder recreation I just can't seem to get it to work.

I have added the condition you suggested and it is now running but creating new folders and adding a more of the name than is required. Not sure where to go from here. I've tried adding and removing different conditions.

Image
Viboxing
 
Posts: 7
Joined: Fri Aug 25, 2023 3:56 am

Can you post the rules as you have them now?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Viboxing
 
Posts: 7
Joined: Fri Aug 25, 2023 3:56 am

I get the feeling that the results you are seeing are from a previous version of the rule. If you are still seeing it, please go through the troubleshooting guide here and post the results: https://www.noodlesoft.com/kb/hazel-tro ... ing-guide/
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

So the rule matches but I think the main issue is that the "-Suffix" element is being seen as the whole final part of the name rather than the last part and including that rather than just the final part of the name. It's also not treating each final suffix individually meaning that "-Robinia" for example is also being applied to a file that would have the suffix "-Balfour".

Logs are here: https://we.tl/t-25hCsUvi8f


Image
Viboxing
 
Posts: 7
Joined: Fri Aug 25, 2023 3:56 am

In the rule preview, click the green checkmark for the matches condition. That will show you what got matched against the suffix attribute.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

This is what the suffix attribute is showing as which is fine in theory but I don't understand why it's creating a new folder and adding that whole suffix to the end and not treating all my file names differently. I only need it to capture that last word after the last dash as the suffix.

Image
Viboxing
 
Posts: 7
Joined: Fri Aug 25, 2023 3:56 am

Can you show me what pattern you have for the suffix attribute?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Open Discussion