MacOS – How to copy a selection of files from multiple folders into multiple folders

androidfindermacosterminal

I am developing an Android-app in OS X, and want to use some third-party icons. I have downloaded and extracted the icons into this folder structure:

  • drawable-mdpi
    • ic_icon1.png
  • drawable-hdpi
    • ic_icon1.png
  • drawable-xhdpi
    • ic_icon1.png
  • drawable-xxhdpi
    • ic_icon1.png

I want to copy the files named ic_icon1.png from each directory into my own folder structure with the same folders, ignoring the rest of the icons in the source folders. How can I accomplish this using Finder or Terminal?

Best Answer

You can use gcp from homebrew for this. Install gcp with

brew install coreutils

Then You can make something like this:

gcp --parents drawable*/ic_icon1.png /path/to/output/dir

This will copy all ic_icon1.png preserving directory tree.

From man gcp:

   --parents
          use full source file name under DIRECTORY