Delete folders/subfolders after processing?

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

Moderator: Mr_Noodle

Delete folders/subfolders after processing? Tue Apr 10, 2012 12:40 pm • by kristin
Hello.

I have a folder where students drop their projects (photography). They typically drop in a folder containing two sub-folders — one subfolder contains .doc files and the other contains .jpg files. Right now I have Hazel going through the folder (and subs) and moving the .doc and .jpg files to another folder, but I'm looking for a way to "clean up" (ie. delete) these empty folders once processed. Is this possible?

Ideally, they would be deleted immediately after processing, but I'd also be happy if these could be deleted after a set time has expired — say, 1 day or something like that — since they're just empty folders at that point.

Any help would be appreciated.
Thanks,
Kristin.
kristin
 
Posts: 23
Joined: Tue Apr 10, 2012 12:34 pm

Yes they can! And it's actually very simple:

I'll assume that your folders are this:

PARENT / Docs
PARENT / JPGs


Where the PARENT folder is the folder you are monitoring.


Code: Select all
If (all) of the following are true for (current file or folder)
     Kind IS Folder
     Size IS 0 bytes

Then
     Move to TRASH
     Send Growl Alert "Empty folders have been cleared from PARENT"
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Actually, this is how I have it set up:

PARENT/STUDENT_NAME/DOCS
PARENT/STUDENT_NAME/JPGS

And this is what I currently have to sort/move the files:

Code: Select all
RULE #1
If (all)...(current file or folder)
Kind IS Folder

Then
Run rules on folder contents

RULE #2 (moves JPG & DOC files to StudentFiles folder)
If (any)...(current file or folder)
Extension IS jpg
Extension IS doc

Then
Move to folder StudentFiles

RULE #3 (delete non-JPG & DOC files [thumbs.db from Windows machines, etc.])
If (any)...(current file or folder)
Extension IS NOT jpg
Extension IS NOT doc

Then
Move to Trash


This seems to have done the trick in terms of sorting the files and deleting unwanted files (my rules are a bit more complex, taking into account .docx extensions, etc., but I've kept them simple for this thread).

I tried adding the code you posted, but it didn't seem to do anything (I think because of my RULE #1). What did work, however, was having the folder delete any top-level folders that were added based on a set time (ie. delete any folders added 1 day ago) — I did this by adding a new rule (before RULE #1 above) as follows:

Code: Select all
NEW RULE #1 (delete folders added more than 1 day ago)
If (all)...(current file or folder)
Kind IS Folder
Date Added IS NOT IN THE LAST 1 DAYS

Then
Move to Trash


Again, not instant, but it keeps the monitored folder auto-clean.
k.
kristin
 
Posts: 23
Joined: Tue Apr 10, 2012 12:34 pm

Nix that, I had an error in the rule you posted — it now works! Thanks!
kristin
 
Posts: 23
Joined: Tue Apr 10, 2012 12:34 pm


Return to Support