Page 1 of 2

How to get Hazel to go into subfolders

PostPosted: Thu Mar 05, 2009 4:13 pm
by Mr_Noodle
[NOTE: this post is superceded by this page in the user guide: Processing Subfolders

This question comes up a lot so I thought I'd answer it here and set it as sticky so that it's in a prominent place. Please make sure to read the whole thing before posting any questions about subfolders. Of course, if you have additional questions or suggestions, please post them.

Can Hazel go into subfolders?

Yes.

How?

In the simplest case, just create a rule like the following:
subfolder-figure1.png
subfolder-figure1.png (18.97 KiB) Viewed 185420 times

How this works is when Hazel encounters a folder, it will go into it and run its rules on the files inside as it was doing with the top level folder. The "Run rules on folder contents" action only applies to folders and tells Hazel that it should descend into this folder.

For example, if you have a folder with subfolders A, B and C and you have rules 1, 2, 3 and 4 in your rule set. Let's say rule 1 is the rule described above. When Hazel hits folder A, it will go inside it and then try and apply rules 1, 2, 3, 4 on all the files and folders inside it. That also means that for any folders inside A that it finds, Hazel will descend into them as well (as dictated by rule 1). When it pops back out, it will do the same for subfolders B and C as it gets to them.

Now how does it not work?

Remember the above is not magic in that it is a rule just like any other. The ordering matters. If you have a rule matching folders before this one, this one will not be run. Also, you can't mix file types into the same rule. A common mistake is:
subfolder-figure2.png
subfolder-figure2.png (33.51 KiB) Viewed 185420 times

Here, the logic for two different rules are being combined into one rule. Chances are, a Music file cannot be a folder at the same time. Also, the "Run rules on folder contents" only makes sense when run against folders so won't make sense when run against a file. Lastly, you probably don't want your folders moved into the "Music" folder.

The solution is to split them up into separate rules.

What if I only want Hazel to apply rules at the top level/level below the top level/etc.?

One thing Hazel does when descending is keep track of how deep it is in the folder tree. This is the "Subfolder depth". Starting at the top level, the subfolder depth is 0. Subfolders from there have a depth of 1 and so on. You can apply it to the folder rule above to limit how far down Hazel goes or you can use it in your rules to process your files, in which case, Hazel will still go as deep as it wants but that rule will only apply to files at certain levels that you specify.

Note: There is a bug in version 2.2.4 and earlier where the preview won't accurately show the effects of filtering on subfolder level. This does not affect how the rules will actually execute. This has been fixed in 2.3.

Can I download this rule?

You sure can. First off, if you are not quite sure how this all works, I advise you do the following:
  • Stop Hazel (either via the menubar or the button in the "Info" tab)
  • Set up your rules.
  • Preview them (the preview item is in the cog/gear pull-down menu)
  • When you are satisfied with the preview, start Hazel again.

People tend to be surprised when using this for the first time, hence the above procedure.

You can download the rule here:
subfolder.hazelrules
(1.48 KiB) Downloaded 26686 times


After downloading, double-click the file or drag it into your rule list.

Enjoy.

Re: How to get Hazel to go into subfolders

PostPosted: Fri Feb 25, 2011 4:40 pm
by venanzio
Please elaborate as I cannot get this to work at all.

I don't know where to place or where you are referring to where to place rules 1,2,3 etc..

I want to go into the subfolder and if the file is a music file move to x
if the file is pdf move to y
if file is doc move to z,
etc.

your example says that we can't do that.

if correct, then what utility does moving into the subfolder have if you can't run a rule?

thanks

Re: How to get Hazel to go into subfolders

PostPosted: Mon Feb 28, 2011 1:12 pm
by Mr_Noodle
You place the rules in the same list. You should not think in terms of doing everything in one rule.

I suggest doing the following:

- Create a test folder for Hazel to watch.
- Use the subfolder rule above exactly as-is (do not modify anything).
- Add a rule after the above rule to color any file blue.

Now, play with adding files and using the preview function to see how it works. From there, play with adding a criteria for subfolder level so you can see how that interacts with the above.

Otherwise, maybe you need to clarify your questions as it doesn't quite make sense to me.

Re: How to get Hazel to go into subfolders

PostPosted: Tue Mar 08, 2011 2:27 pm
by mitchbvi
I am having trouble getting this to work as outlined. Created three folders put one file in each then entered the "Go into subfolders" rule than one to color files blue. That worked on all three files. When I added a subfolder depth to the "co into subfolders" it would color the 1st files in the first folder blue and not the other 2. I tried reversing the order of the rules "color blue" first but that did not make any difference. Also tried changing the "Go into subfolders" rule from meeting all the conditions to any that just colored all three files blue irrespective of the depth I set.

thanks

Peter

Re: How to get Hazel to go into subfolders

PostPosted: Wed Mar 09, 2011 6:03 pm
by Mr_Noodle
It might be better to post in the support forum instead of here. Also, I've already responded to you in email so at some point I'll remove these articles.

Re: How to get Hazel to go into subfolders

PostPosted: Fri Jun 10, 2011 9:30 pm
by infinitejones
This appears not to work if the folder name contains a dot - when I previewed the rule on a folder full of subfolders, it selected all of them apart from the one called R.E.M (with the dots). When I renamed the folder to REM, and previewed it again, it worked fine.

Is that by design or a bug?

Re: How to get Hazel to go into subfolders

PostPosted: Tue Jun 14, 2011 2:34 pm
by Mr_Noodle
It seems to work for me. I suggest you email a copy of your rules as well as the output of your rule preview. Also, I suspect this is not specific to subfolder traversal so I'd advise posting in a separate thread in the future.

Re: How to get Hazel to go into subfolders

PostPosted: Sun Oct 09, 2011 7:41 am
by peterderren
Hi Mr Noodle,

I can't get this to work in a way that is useful for what I'm trying to achieve. Maybe there is something I am doing wrong?

What I want to do is have subfolders within certain other folders grey when they are empty. What I've tried is to build a rule which checks whether a folder is empty (actually checking for it being less than 100kb in size because of course 'Number of Items' counts subfolders even if empty). If a folder is empty then the action is to set the label colour to grey.

However, I don't want the main folders to go grey because it gets confusing, so I am trying to use rules to exclude the first levels of the structure. I've tried the 'Subfolder Depth' item, but the problem there is that because they inherently exclude the first tiers Hazel doesn't then run the same rule set on the subfolders. I think..?

What I had hoped to do was:

All conditions to be met:
- Size is less than 100KB
- Subfolder Depth is greater than 3
- Kind is Folder
Action:
- Set Colour Label to Grey


Anyway, I'm sure you can see immediately what I should be doing instead.

Thanks in advance for your help - I'm looking forward to all the flexibility this tool of yours brings.

Best,
P

Re: How to get Hazel to go into subfolders

PostPosted: Sun Oct 09, 2011 12:36 pm
by Mr_Noodle
I think you may have a problem with the ordering of rules. This rule should appear before the rule to descend into the folders. Use the rule preview to check your work.

Re: How to get Hazel to go into subfolders

PostPosted: Tue Jun 26, 2012 10:21 pm
by dzg
Help me make this work...

I have a folder called MEDIA.
Inside that are many folders, PROJECT1, PROJECT2, ...
Some PROJECT folders contain folders called PROJECTX_OUTPUT.

I want Hazel to:
Every time a new Quicktime Movie is added to a PROJECTX_OUTPUT folder, I want that Movie to be opened with MPEG Streamclip.

I tried to set this up with the Run Rules on FOlder Content thing ... but I can't get it to work. It tries to open the OUTPUT folder, NOT the Movie within!

Re: How to get Hazel to go into subfolders

PostPosted: Thu Jun 28, 2012 3:29 pm
by Mr_Noodle
First off, please post a separate thread in the support forum. Make sure to include the rules. Also, make sure you read the article fully. Many people claim to read it and end up doing the exact thing the article tells you not to (note that there's an image with a red X through it. That means "don't do this").

Re: How to get Hazel to go into subfolders

PostPosted: Thu Jul 05, 2012 3:11 pm
by robwired
Hi,

I'd really like to use this functionality in the most basic way but it's just not working.

I have successfully set Hazel up to watch a folder and to move files that match a condition to move to another folder on my system.

Here is what I have happening on a folder on my system named Torrents

Name: Television- Avengers (avi)

if all of the following conditions are met for the file or folder being matched
Name contains Avengers
Extension is avi

Do the following to the matched file or folder:
Move to folder Avengers

This works 100%.

Where I am having a problem is when I set up to Watch for Subfolders as an additional rule prior to the above rule.

Name: Watch for Subfolders
If any of the following conditions are met for "the file or folder being matched" or "all of its sub-files and folders"

Kind is folder

Do the following to the matched file or folder:
Run rules on folder contents.

As above, I have tried both settings of "the file or folder being matched" and also "all of its sub-files and folders" and neither is working.

It gets worse. If I have this rule loaded then my primary rule stops working for files that go into the Torrents folder as well.

In order to get that rule working again I have to uncheck or remove this rule and then reboot my system.

I'm on version 3.0.8. Is this a bug, something that might be fixed in an update or am I doing something wrong?

Re: How to get Hazel to go into subfolders

PostPosted: Fri Jul 06, 2012 2:05 pm
by Mr_Noodle
First off, I suggest starting a new thread. I want to avoid long discussions for the sticky articles.

Do not use "all of its sub-files". Do as the article says exactly.

Please read the other sticky article about troubleshooting. Check the preview and logs as specified there. If you still can't figure it out, then please start a new thread instead of posting here.

Re: How to get Hazel to go into subfolders

PostPosted: Tue Jul 24, 2012 10:04 am
by doug4knfpu
The article worked perfectly for me. Thank you noodle :)

Re: How to get Hazel to go into subfolders

PostPosted: Thu Feb 21, 2013 9:59 am
by vincentpolisi
Works perfectly as described!

If you're trying to have it go into a folder and extract, move, copy, files inside the folder simply create two rules.

Duplicate or copy the first rule above and then create a second rule.

For example:

I needed it to go into a folder that contained several dozen sub folders and copy all of the images to another folder so I could have all of the images in one folder versus scattered over several dozen.

Select the Folder you want on the left hand side folder column (Folder A)
Rule 1: Run rules on folder contents (Kind is folder)
Rule 2: I named this rule "Images" (Kind is images) (Copy to Folder B)

Ran it. It went into the sub folders and copied all of the images to Folder B