Help Match Folders

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Help Match Folders Wed Jan 30, 2019 3:14 pm • by IVG
So I am a bit of a newbie to Hazel but am loving all the possibilities...

I need help doing something. I have a folder structure like this:
PARENT FOLDER
I. Company 1
____II. folder1
____II. folder2
______III. folder x
______III. folder y
____II. folder3
I. Company 2
____II. folder1
____II. folder2
______III. folder x
______III. folder y
____II. folder3

this structure is repeated many times for many companies.

I need to create a rule that will scan all the subfolders in the parent folder, find subfolder that contains "folder2" in its name, and then apply tags to all files inside the subfolder and its subsubfolders...

I can't seem to figure out how to do it...

I have a "GOTOSUBFOLDER RULE" where it says IF kind IS folder THEN Run Rules on Folder Contents
then I have another rule that says IF kind IS Folder AND NAME contains "folder 2" THEN Run Rules on Folder Contents
and a third rule IF any file AND kind IS NOT folder THEN add TAG

but this tags everything in all folders...

so I guess the issue I can't limit the ADD TAG rule only to subfolders of a parent folder that contains "folder2"... I am sure it is possible to do, I just can't figure it out...

please help!
IVG
 
Posts: 12
Joined: Tue Jan 22, 2019 5:00 pm

Re: Help Match Folders Thu Jan 31, 2019 11:51 am • by Mr_Noodle
Note that the second rule is unnecessary as it's already covered by the first.

You can use nested conditions to match a file based on its parent. Look it up in the manual. You'll want to do something like:
Code: Select all
If (all) are met
    If (all) are met for (the enclosing folder)
        Name is "Folder 2"
Mr_Noodle
Site Admin
 
Posts: 7976
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Help Match Folders Thu Jan 31, 2019 2:23 pm • by IVG
Mr_Noodle wrote:Note that the second rule is unnecessary as it's already covered by the first.

You can use nested conditions to match a file based on its parent. Look it up in the manual. You'll want to do something like:
Code: Select all
If (all) are met
    If (all) are met for (the enclosing folder)
        Name is "Folder 2"


Thanks for this, but as I understand this, is only going to work when going one level deep, because the enclosing folder for sub sub folder will not have the name "folder 2"...

lvl1
___folder 1
___folder 2
______folder a
______folder b
_________folder i
_________folder ii
______folder c
___folder 3

so in this example folder's a, b and c would match, but folders i and ii will not go deeper...

I have been trying to do the following (but I can't get it to work)

Rule 1. Go To Subfolder IF kind IS folder THEN run rules on contents

Rule 2. IF KIND IS folder AND IF enclosing folder NAME CONTAINS xxx THEN run rules on folder contents

Rule 3. IF KIND IS NOT folder ADD TAG yyy AND Continue matching rules

in reality i have a very deep decimal folder structure such as

lvl 1 - 10-20xxx
___lvl2 11
________lvl3 11.01
________lvl3 11.02
________________lvl4 11.02.A
________________lvl4 11.02.B
_________________________lvl5 11.02.B.a
_______________________________lvl6 folder 1
_______________________________lvl6 folder 2
________________________________________lvl6 subfolder 1
________________________________________lvl6 subfolder 2
_______________________________lvl6 folder 3
_________________________lvl5 11.02.B.c
_________________________lvl5 11.02.B.d
________________lvl4 11.02.C
________lvl3 11.03
___lvl2 12
___lvl2 13

and it the naming schema is also similar so lets say I have folder called "Legal" in many lvl2 or lvl3 folders and I want to tag all the files inside them and their subfolders with a tag "legal" - this is the ultimate result I want to achieve. a recursive scan to find a folder that matches a condition and then tag all files inside, no matter how deep the file structure goes...
IVG
 
Posts: 12
Joined: Tue Jan 22, 2019 5:00 pm

Re: Help Match Folders Fri Feb 01, 2019 11:46 am • by Mr_Noodle
Another option is to limit what folders it goes into. I guess this was what you were trying originally but you need to add conditions to it for it to work.

Something like:
Code: Select all
  If (any) are met
      Subfolder level is 0
      Subfolder level is greater than 1
      If (all) are met
          Name is Folder
          Subfolder level is 1
  Do
     Run rules on folder contents


That might requires some tweaking but should give you the general idea. Also, the rule to tag should have a "subfolder level" condition to only tag stuff that is deeper than folder 2.
Mr_Noodle
Site Admin
 
Posts: 7976
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Help Match Folders Fri Feb 01, 2019 1:37 pm • by IVG
Mr_Noodle - again thanks for the help - however this is not really going to cut it for me... unfortunately the depth of the folder i need to select varies - and I really wanted to filter it by name... so i guess there isn't a work around unless I would have a shell or other script (and I don't know how to write one) so I guess I am stuck...
IVG
 
Posts: 12
Joined: Tue Jan 22, 2019 5:00 pm

Re: Help Match Folders Fri Feb 01, 2019 8:41 pm • by Robert
IVG wrote:Mr_Noodle - again thanks for the help - however this is not really going to cut it for me... unfortunately the depth of the folder i need to select varies - and I really wanted to filter it by name... so i guess there isn't a work around unless I would have a shell or other script (and I don't know how to write one) so I guess I am stuck...


Yes I just found a solution with a shell script.
You need two rules:

1. ➔ For Tagging files which are not folders and have a certain name (here "legal") within the path.
Image
Add in passes shell script:
Code: Select all
string="$1"
if [[ $string == *"legal"* ]];
then
    exit 0
else
    exit 1
fi

For "legal" (within the shell script) you can take any name within the path of the file you want to tag.

2. ➔ For Processing the first rule in the depth of the directory.
Image
"Behind all the inhuman aspects of automation (...) its real possibilities appear: the genesis of a technological world in which man can finally withdraw from (...) the apparatus of his labor – in order to experiment freely with it." /Marcuse
Robert
 
Posts: 52
Joined: Sun Dec 16, 2018 8:05 am

Re: Help Match Folders Sat Feb 02, 2019 5:40 pm • by IVG
Robert, that script didn't work for me but it gave me an idea of how to do that without a script... there is an option to chose "other" in the conditions and you can find "File Pathname" and then set that it "contains" certain word, such as "legal" and that works!!!! thank u for your help and pointing me to the right direction!
IVG
 
Posts: 12
Joined: Tue Jan 22, 2019 5:00 pm

Re: Help Match Folders Sat Feb 02, 2019 8:24 pm • by Robert
Aaah great! I did not know that either!

(Strangely the shell script does the same thing for me ... but I am glad I could hint you with looking for the file path.)
"Behind all the inhuman aspects of automation (...) its real possibilities appear: the genesis of a technological world in which man can finally withdraw from (...) the apparatus of his labor – in order to experiment freely with it." /Marcuse
Robert
 
Posts: 52
Joined: Sun Dec 16, 2018 8:05 am


Return to Support

cron