move an entire folder tree

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

Moderator: Mr_Noodle

move an entire folder tree Sat Jan 05, 2013 4:40 pm • by Pyrman
Just got Hazel so I am very new to it...

I searched and searched, but couldn't find how to do this...( I also read the subfolder sticky... didn't help)

My downloads folder contains a number of folders, each of which contains multlple levels of subfolders and files.
I want to scan each of these folders and all of their subfolders, and if a particular kind of file is found anywhere in the tree, I want to move the entire tree out of the downloads folder to a different folder... Can this be done entirely with Hazel?
Pyrman
 
Posts: 3
Joined: Sat Jan 05, 2013 4:17 pm

Re: move an entire folder tree Sun Jan 06, 2013 3:40 pm • by a_freyer
how deep would this "triggering" file be?
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: move an entire folder tree Sun Jan 06, 2013 7:39 pm • by Pyrman
Typically it would be in the 1st or 2nd level....
And... it can stop once it finds the first file, since that would trigger the whole directory to be moved anyway...

An example would be to move movies or ebooks... if I download a series of ebooks from one of my favourite authors, the download is broken down as such...

downloads
downloads/author
downloads/author/series1
downloads/author/series1/book1
downloads/author/series1/book1/...file.epup <- this is the trigger file
downloads/author/series1/book1/...other files
downloads/author/series1/book2
downloads/author/series1/book2/...file.epup <- this is the trigger file
downloads/author/series1/book2/...other files

downloads/author/series2
downloads/author/series2/book1
downloads/author/series2/book1/...file.epup <- this is the trigger file
downloads/author/series2/book1/...other files
downloads/author/series2/book2
downloads/author/series2/book2/...file.epup <- this is the trigger file
downloads/author/series2/book2/...other files

so in this example... I would like the entire directory "author" moved to my ebooks directory. Once there, I can have a separate rule to perform processing. The key is to get the author directory moved over as soon as a valid epup file is found anywhere in its sub folder tree.
Pyrman
 
Posts: 3
Joined: Sat Jan 05, 2013 4:17 pm

Re: move an entire folder tree Sun Jan 06, 2013 8:03 pm • by a_freyer
Well, I am sure that there are other ways of doing this (for instance using built in Hazel functionality cited by Mr_Noodle below), but we can do this with a "passes shell script" condition:

Code: Select all
if (all) of the following conditions are met for (the file or folder being processed):
     kind is folder
     passes shell script (embedded script)

Do the following to the matched file or folder:
     Move somewhere else


Script:

Code: Select all
if [ "$(/usr/bin/find "$1"  -type f -print | grep -c ".epup")" -gt 0 ]; then exit 0; else exit 1; fi


Psuedocode Explanation:
IF find and print all directories and files within this folder AND one ore more of those includes "epup"
THEN exit 0 so that Hazel moves this folder
ELSE exit 1 so Hazel ignores this folder
Last edited by a_freyer on Mon Jan 07, 2013 4:17 pm, edited 1 time in total.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: move an entire folder tree Mon Jan 07, 2013 3:57 pm • by Mr_Noodle
Can't you do something like this?
Code: Select all
If (all) match for (any sub-file)
   <whatever conditions match the file you are looking for>

Move to wherever

This will move the folder if a sub-file anywhere underneath it matches whatever conditions.
Mr_Noodle
Site Admin
 
Posts: 11951
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: move an entire folder tree Tue Jan 08, 2013 11:14 pm • by Pyrman
Thanks... Both options worked....
Appreciate the help...
Pyrman
 
Posts: 3
Joined: Sat Jan 05, 2013 4:17 pm


Return to Support