我正在尝试找到一个命令,该命令可以查找并将具有给定名称的文件复制到另一个文件夹,但路径略有不同。
例如,有 4 个 PNG 文件副本,名为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
我想将其复制到
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
即找到的文件的正确 dpi 版本被复制到目标目录的正确 dpi 版本
有人知道如何使用 find 命令或脚本等来执行此操作吗?
短暂性脑缺血发作
答案1
rsync 方式:
rsync -avh --include="*/" --include="*.png" --exclude="*" app/ feature/name1/
测试:
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/
树应用程序
app/
└── src
└── main
└── res
├── drawable-hdpi
│ └── ic_arrow.png
├── drawable-mdpi
│ └── ic_arrow.png
├── drawable-xhdpi
│ └── ic_arrow.png
└── drawable-xxhdpi
└── ic_arrow.png
树特征
feature/
└── name1
└── src
└── main
└── res
├── drawable-hdpi
├── drawable-mdpi
├── drawable-xhdpi
└── drawable-xxhdpi
rsync 命令
rsync -avh --include="*/" --include="*.png" --exclude="*" app/ feature/name1/
最终结果(树特征)
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