Rule for synchronizing folders containing sub-folders

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

Moderator: Mr_Noodle

Hello

How can I synchronize/copy a folder with sub-folders containing JPEG-files to an external HD preserving the same folder structure. So, it is just a simple backup process with one way synchronizing. Thanks for your answers

Andreas
andreasj
 
Posts: 1
Joined: Mon Apr 30, 2012 3:19 am

First off, please do not post questions to the tips forum. There's a sticky article up top telling you not to do this.

As for your question, have Hazel monitor the folder containing the folder you want to sync. Then make a rule as follows:
Code: Select all
If all of the following are met for current file
    Kind is folder
    Date modified is after date last matched
    If all of the following are met for any sub-file
        Date modified is after date last matched
Then
  Sync


You may want to add additional conditions to match the specific folder in question. This will sync for every single change. You may also want to consider, instead, syncing on a schedule.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I tried this rule. It worked with test folders but not with my Documents folder which I'm trying to mirror to iDisk. I make changes to documents within the folder on my Mac but Hazel doesn't catch them.

Any suggestions?

Documents Folder on Mac
all conditions met for this file or folder being matched
Kind is Folder
Date last modified is after date last matched
If all conditions met for any of its subfiles of subfolders
Date last modified is after date last matched
Do following
Sync
Send Growl notif.
Mondozer
 
Posts: 20
Joined: Thu Feb 24, 2011 3:52 pm

Actually, just caught an error in the rule I posted. To make sure you catch everything you should do:
Code: Select all
If all of the following are met for file being matched
    Kind is folder
    If any of the following are met for file being matched
        Date modified is after date last matched
        If all of the following are met for any sub-file
            Date modified is after date last matched
Then
  Sync


Sorry about that.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr. Noodle:

Thank you so much. The revised rule works as advertised.

Getting subfolders right is such a challenge for non programmers. I hope you will post this rule to the subfolders sticky where others can easily find it.

Kind regards,
M.
Mondozer
 
Posts: 20
Joined: Thu Feb 24, 2011 3:52 pm

Guys, sorry for a perhaps dumb question, but: How do I create an additional "if"-statement inside another "it"-statement in Hazel?
toadle
 
Posts: 2
Joined: Wed Jun 20, 2012 9:57 am

In the rule folder <option-click> the plus sign at the end of the first rule.
Mondozer
 
Posts: 20
Joined: Thu Feb 24, 2011 3:52 pm

Thx - a real pro-feature :-)!
toadle
 
Posts: 2
Joined: Wed Jun 20, 2012 9:57 am

One question on the updated copy of the rules. As written the rule will skip over the top level files. This is because of the first "Kind is Folder" Is there a way to fix that?

If all of the following are met for current file
Kind is folder
Date modified is after date last matched
If all of the following are met for any sub-file
Date modified is after date last matched
Then
Sync
wlai
 
Posts: 1
Joined: Fri Sep 14, 2012 4:11 pm

Get rid of the "Kind is folder" condition.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I stumbled across this while attempting to find an alternative to RAID 1. I have two external drives for storing media for my home media server. I am looking for an alternative to RAID, since it crashed my box when I tried using it. All my files will be in sub-folders for organization purposes, usually 2-3 folders deep, depending on the file. Will Hazel be able to handle syncing that deep with the script you provided?
Also, noticed that it appears some of the options have changed since the script above was provided, for example, the second, indented If statement refers to "file being matched", but that's not an option in the current version. It appears to have been changed to "the current file or folder". Similarly, the second nested If statement refers to "any sub file", but the current option is "any of its subfiles or subfolders". Will the script still work as expected with these differences?
PackDude
 
Posts: 6
Joined: Thu Aug 22, 2013 2:20 pm

I used shorter names in my description. Don't be worried about everything matching literally, instead looking at the actual meaning of it.

And yes, the script itself has no notion of any bounds as far as how deep it will go. Again, though, I suggest analyzing the rule so that you have a better understanding of it and testing it before deploying it.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support