Deleting Empty Folders

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

Moderator: Mr_Noodle

Deleting Empty Folders Sat Aug 17, 2013 3:36 am • by mrtoner
I'm sorry. Really. This question has come up in the past many times and I still can't get this working even after reading the prior answers.

I've got four rules:

#1 - Runs rules on folder contents
#2 - Checks to see if the enclosing folder is "Incoming" and the file was not added today. Moves the file to a "Processed" folder in the watched folder. Works as desired.
#3 - Checks to see if the folder is not "PDFs" and the file is a PDF. Moves the file to the "PDFs" folder in the watched folder. Works as desired.
#4 - If all of the following conditions are met:
- If all of the following conditions are met for the current file or folder: (this is probably redundant, but the rule doesn't work without it, either)
- Kind is Folder
- Size is 0 bytes
- Subfolder depth is greater than 5
Do the following:
- Set color label

When I preview the rules, the empty folders match rule #1 but not #4. And the action doesn't occur. However, the matching attributes are correct when I examine them: Kind, Folder; Size, 0B; Subfolder depth, 7.

What simple thing have I overlooked?
mrtoner
 
Posts: 17
Joined: Thu Mar 15, 2012 11:54 pm

Re: Deleting Empty Folders Mon Aug 19, 2013 1:49 pm • by Mr_Noodle
The first rule to match is the one that gets executed. I'm guessing your first rule matches all folders, so it will catch all the folders before they get to the rules further down. You should reorder the rules to take this into account.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Deleting Empty Folders Mon Aug 19, 2013 5:33 pm • by mrtoner
The problem is that there is a hierarchy of folders:

Watched folder
- First subfolder
- - Another
- - - Yet Another
- - - - And Still Another
- - - - - One More
- - - - - - Next one
- - - - - - - A Year Folder
- - - - - - - - A Month Folder
- Incoming
- PDFs
- Processed

I can make this simpler, I suppose, by watching the "Next one" folder instead (since the app that's creating this structure will just recreate it). However, as Hazel moves PDFs out of each of the "Day" folders I want it to clean up after itself and delete the empty folders. Is there some way to traverse the folder structure and still act on each folder?

(In case you're interested, the app mentioned previously scans the Incoming folder and creates the EA2 hierarchy. It's odd. Rule #2 moves the files out of Incoming and into Processed. Rule #3 moves files out of the EA2 hierarchy. I want rule #4 to remove the empty folders.)
Last edited by mrtoner on Fri Aug 23, 2013 3:48 pm, edited 1 time in total.
mrtoner
 
Posts: 17
Joined: Thu Mar 15, 2012 11:54 pm

Re: Deleting Empty Folders Tue Aug 20, 2013 1:41 pm • by Mr_Noodle
Just stick the rule to move empty folders up before the other one. It probably has more specific conditions on what kind of folder, so it should appear before any blanket folder rule.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Deleting Empty Folders Fri Aug 23, 2013 2:17 am • by mrtoner
Hmm, okay. I thought the "Run rules on folder contents" action was necessary act on the subfolders.

It looks like moving rule #4 to #1 (shifting the others down) should work (I also added conditions to ignore the Incoming, Processed and PDFs folders), but it doesn't. When I preview the rules, my year folders show that "Delete empty folders" is matched, but the month folders below those aren't listed -- and the "Set color label" action doesn't happen.
mrtoner
 
Posts: 17
Joined: Thu Mar 15, 2012 11:54 pm

Re: Deleting Empty Folders Fri Aug 23, 2013 12:29 pm • by Mr_Noodle
That rule is necessary to go into folders, but if the folder is empty, why would you need to go into it?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Deleting Empty Folders Fri Aug 23, 2013 4:11 pm • by mrtoner
Looking at the folder hierarchy above, rule #4 (perviously rule #3) moves all PDFs out of the Month folders and into the PDFs folder. This leaves me with multiple empty Month folders that I want to delete. When the Month folders are deleted, I want to delete the Year folders.

You state that the "Run rules on folder contents" rule (now rule #2) is necessary to go into folders, so I'm wondering how Hazel can delete nested empty folders (rule #1) without going into the folders above the empty ones?

If it is as you say, why is rule #1 not deleting (or, in this test, coloring) the folders? Here's the rule:

Image

the preview:

Image

and the folder structure:

Image
mrtoner
 
Posts: 17
Joined: Thu Mar 15, 2012 11:54 pm

Re: Deleting Empty Folders Mon Aug 26, 2013 11:33 am • by mrtoner
Hmm. It appears that Hazel started coloring the folders a few minutes after my last post. The log shows:

Code: Select all
2013-08-23 21:45:20.214 hazelworker[50584] 2011: Rule Delete Empty Folders matched.
2013-08-23 21:45:20.217 hazelworker[50584] 2012: Rule Delete Empty Folders matched.
2013-08-23 21:45:20.220 hazelworker[50584] 2013: Rule Delete Empty Folders matched.
mrtoner
 
Posts: 17
Joined: Thu Mar 15, 2012 11:54 pm

Re: Deleting Empty Folders Tue Aug 27, 2013 1:29 pm • by Mr_Noodle
If you are going by size, it ignores empty folders within folders so a folder that only has empty folders underneath it will be considered empty.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support