Page 1 of 1

Rename a folder based on children-files' contents

PostPosted: Sat Nov 28, 2020 10:39 am
by awaldraff
I live in Colombia. Our government has implemented a "digital invoicing" system for independent workers which basically has everyone trading zip files around. Inside the zip files is an xml file with the contents of the invoice, and a PDF file, which is in essence a "visualization" of said invoice. Most files are generated by a central (government owned) system that names files with the following scheme xml-nationalID#-invoice#.

I would like hazel to rename my invoices (the zip file) to YYYYMM - invoice# - invoicee.

What I think is the best way to do it is:
1. Open the zip file
2. Go into the folder
3. Read the xml file and save the invoicee as a token
4. rename the folder name using the token
5. archive the folder

I have not been able to do step 4. One running the rule inside the folder, there is no way to rename the parent folder. Or is there a fancy way of doing it?

Re: Rename a folder based on children-files' contents

PostPosted: Sat Nov 28, 2020 12:13 pm
by Mr_Noodle
Instead of having a rule which matches a file and renames its parent folder, instead, have a rule which matches a folder and renames it based on the child. Look up "nested conditions" in the manual. You can set up a nested condition which is applied against sub-files in the folder. You can then use a match pattern there and then use that in the Rename action (which is applied to the folder).