0

I am trying to find a command that finds and copies files with a given name to a another folder but with a slightly different path.

For e.g. there are 4 copies of PNG files named ic_arrow.png

app/src/main/res/drawable-xhdpi/ic_arrow.png
app/src/main/res/drawable-xxhdpi/ic_arrow.png
app/src/main/res/drawable-hdpi/ic_arrow.png
app/src/main/res/drawable-mdpi/ic_arrow.png

and I would like to copy this to

feature/name1/src/main/res/drawable-xhdpi/ic_arrow.png
feature/name1/src/main/res/drawable-xxhdpi/ic_arrow.png
feature/name1/src/main/res/drawable-hdpi/ic_arrow.png
feature/name1/src/main/res/drawable-mdpi/ic_arrow.png

i.e. the right dpi version of the found file gets copied to the right dpi version of the target directory

does anyone know how I can do this with the find command or a script etc?

TIA

0

The rsync way:

rsync -avh --include="*/" --include="*.png" --exclude="*" app/ feature/name1/

Testing it:

mkdir -p app/src/main/res/drawable-xhdpi/ app/src/main/res/drawable-xxhdpi/ app/src/main/res/drawable-hdpi/ app/src/main/res/drawable-mdpi/
touch app/src/main/res/drawable-xhdpi/ic_arrow.png app/src/main/res/drawable-xxhdpi/ic_arrow.png app/src/main/res/drawable-hdpi/ic_arrow.png app/src/main/res/drawable-mdpi/ic_arrow.png
mkdir -p feature/name1/src/main/res/drawable-xhdpi/ feature/name1/src/main/res/drawable-xxhdpi/ feature/name1/src/main/res/drawable-hdpi/ feature/name1/src/main/res/drawable-mdpi/

tree app

app/
└── src
    └── main
        └── res
            ├── drawable-hdpi
            │   └── ic_arrow.png
            ├── drawable-mdpi
            │   └── ic_arrow.png
            ├── drawable-xhdpi
            │   └── ic_arrow.png
            └── drawable-xxhdpi
                └── ic_arrow.png

tree feature

feature/
└── name1
    └── src
        └── main
            └── res
                ├── drawable-hdpi
                ├── drawable-mdpi
                ├── drawable-xhdpi
                └── drawable-xxhdpi

rsync command

rsync -avh --include="*/" --include="*.png" --exclude="*" app/ feature/name1/

Final result (tree feature)

feature/
└── name1
    └── src
        └── main
            └── res
                ├── drawable-hdpi
                │   └── ic_arrow.png
                ├── drawable-mdpi
                │   └── ic_arrow.png
                ├── drawable-xhdpi
                │   └── ic_arrow.png
                └── drawable-xxhdpi
                    └── ic_arrow.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.