How to duplicate files while preserving folder hierarchy?

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

Moderator: Mr_Noodle

Got a problem i can't for the life of me figure out how to implement with Hazel or Automator.

Basically i have the following file hierarchy

Foldermain
-foldersub1
--file.txt
--filey.dat
--filec.imp

-foldersub2
--fileu.txt
--filegy.dat
--filedc.imp

... etc etc

Where all the folders and files have different name and are in no way sequential.

I basically want to back up all BUT the .dat files in foldermain to another location while retaining all the folder names, file names and the current folder hierarchy.

Could anyone please help me with this?

Thanks,
Bismar
Bismar
 
Posts: 2
Joined: Tue Aug 25, 2009 9:23 pm

While you can copy whole folders over that won't filter out the .dat files in it. There's no way now of maintaining the folder hierarchy when copying a file over. I'm considering adding a "parent folder" attribute for use in the "Sort in subfolders" attribute. It would represent the path from the top level folder (the one Hazel is monitoring) down to the file in question. You can drop that into any patterns for folders to create on at the destination end.

I actually have been thinking a bit about it recently so let me know if this type of thing solves your problem, and if not, maybe elaborate more on what it is you need.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I'm a little unsure by your post when you mentioned that you can copy whole folders over but not maintaining the hierarchy. Say i have a folder structure like this

Folder A (Hazel Monitored) and in documents
--Folder B
-----file.txt
--Folder C
-----another.txt

etc.

and i would like it duplicated to say a folder in desktop called final.

What and how would you copy 'whole folders' and retain their original folder names?

And the dat part i would have thought its the easiest, by just creating a rule on the folder containing the newly duplicate folders (final in this case), with act on subfolder, and then sending dat files to trash.

The parent idea sounds pretty good, if it would allow us to choose how many 'parents' or 'grandparents' deep we would like. ie

Folder A (Hazel Monitored)
---Folder B
------Folder C
---------Folder D
-------------text.txt

and that i would like to copy to a new location with all the corresponding files and folder names of the 'grandparent' when it finds the text.txt file. Where text.txt file parent would be Folder D, and its grandparent Folder C.
Bismar
 
Posts: 2
Joined: Tue Aug 25, 2009 9:23 pm

If you just set a rule to copy something, if that something is a folder, it will copy the whole thing over wholesale. This is somewhat rough and doesn't let you do things at a finer granularity. For instance, if you only want to copy over files that changed since last time, it won't work since the folder's modification date may not have changed even if some files within it have.

I'm not sure if the parent folder attribute would let you have that much control. When writing the rule, there's no notion of the structure of the folders you are going to run it on ahead of time and you have to provide for cases that don't line up. For instance, what if the rule matches a file at the top level (folder A, in your example), what does it mean to use the folders two levels up? And suppose you have a folder at level E (one below D)? The destination might look like:

Destination
---Folder C
------Folder D
---Folder D
------Folder E

Since from the perspective of a file in E, D is the grandparent. Basically, specifying levels from your current position may not be what you want.

For now, it would be the whole path from A to D. I might provide for just Folder D (the immediate parent) as an extra option if someone can come up with a good case that would need it. If you want just C & D, then you would probably have to have Hazel monitor folder B instead. I guess I could provide a way to specify a new "root" in relation to the top level folder (like the "Subfolder level" attribute when specifying rule conditions). I'd need to think about how that would be done though.

I'm not sure if you're still following at this point but hopefully some of this made sense. If not, let me know and I'll try and clarify.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron