OK. After rather too long walking through the weeds with Terminal...
You have a folder called "Project" on your Desktop and you'd like to duplicate the folder structure, including any custom icons but none the files in it or any subfolders, to "New Project" on your Desktop:
rsync -a -E ~/Desktop/Project/ ~/Desktop/New\ Project --include \*/ --include \Icon\? --exclude \*
-a
gives recursion, the copying of "normal" attributes like permissions, etc. -E
includes extended permissions -- part of which is icon information. Note the trailing /
for the source directory, without that you'll copy the contents but not the directory itself (and so not the icon).
For filters, *
matches everything except a /
. The filters are, in order: include any path that ends with a /
(directories); include anything named "Icon?" (the hidden icon files); exclude everything whose path doesn't end with a /
(all non-directories. Filters are tested in order and first match finishes, so "exclude all files" must come after the icon file test.
But you want to include the files of a subdirectory called "My Files"? Add another includes
filter:
rsync -a -E ~/Desktop/Project/ ~/Desktop/New\ Project --include \*/ --include \Icon\? --include \My\ Files/\* --exclude \*
...which will you the files of "My Files" but not the files in any subdirectory of "My Files" (remember, *
doesn't match a /
). If you want to include the files contained by "My Files" and the files in all its subdirectories then use two *
s, which does match /
:
rsync -a -E ~/Desktop/Project/ ~/Desktop/New\ Project --include \*/ --include \Icon\? --include \My\ Files/\*\* --exclude \*
I'll leave how to use that in a KM action, with variables pumped in as source, target, and may included subdirectories, as an exercise for the Reader. (In other words, I need sleep!)
You'll find much, much, more about rsync
and especially its filters via man rsync
in Terminal.
Edit to add:
Forgot to say -- beware of things you think are files but really aren't! Two obvious ones are applications and RTFD "files" -- both are considered directories on the Unix side, so if you have those in your template you'll end up with orphaned folders. I'm sure there's other software that saves "files" as packages, so test and adjust inclusions/exlusions to suit.