5

I got a folder with a large amount of files with different suffixes in several sub folders.

My automator workflow works as follows:

  1. Ask for Finder Items
  2. Get Folder Contents (sub folder option checked)
  3. Filter Finder Items (for a specific file-suffix)
  4. Copy Finder Items

This works like a charm. But all files are copied in the same root destination folder. I need to keep the the sub folder structure. For Example:

sourceFolder subfolderA fileA.jpg fileB.xls fileC.xls subfolderB fileC.jpg fileD.xls fileE.xls 

Expected result (filter for file suffix .xls):

destinationFolder subfolderA fileB.xls fileC.xls subfolderB fileD.xls fileE.xls 

Current result:

destinationFolder fileB.xls fileC.xls fileD.xls fileE.xls 

Update

I'm a developer. So a shell or AppleScript will be also accepted. :)

3 Answers 3

9
rsync -avh --include='*/' --include='*.xls' --exclude='*' path/to/sourceFolder/ path/to/destinationFolder 

Note the / at the end of the source path, it's important. This solution would add all empty directories, if you don't want them, look at the option --prune-empty-dirs.

With brace expansion you can actually include more filetypes at once, rather than having

--include='*.xls' --include='*.pdf' --include='*.txt' 

you can use

--include='*.'{xls,pdf,txt} 
2
  • great. ty! i will test and come back to it. Commented Feb 18, 2016 at 14:48
  • You can add all the options you want, the important part is the includes–excludes: include all directories (necessary for recursivity) and all .xls files, then exclude everythingn else. If you want more things like --delete add them to your command. Commented Feb 18, 2016 at 15:12
1

I end up with a shell script, that works as requested:

$ find ./sourceFolder -name "*.xls*" -type f -print0 | xargs -0 -I '{}' /usr/bin/rsync -avR "{}" "./destinationFolder/" 
3
  • rsync -avh --include='*/' --include='*.xls' --exclude='*' sourceFolder/ destinationFolder? With brace expansion you can actually include more filetypes --include='*.'{xls,pdf,txt}. Commented Feb 17, 2016 at 23:38
  • @Manuel ty! Any advantages / disadvantages of your solution? Commented Feb 18, 2016 at 8:54
  • That you don't concatenate through pipes, you just call rsync once with the appropiate flags. Commented Feb 18, 2016 at 9:41
0

In a shell script you can use mkbom to make a BOM (bill of materials) file that contains a list of files that you want to copy. Then you can use the ditto command with the --bom option to copy only files listed in the BOM file.

1
  • ty! Any advantages / disadvantages of your solution? Commented Feb 18, 2016 at 8:53

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.