将文件复制到具有特定名称的多个文件夹(Automator或脚本)

时间:2016-12-01 18:25:49

标签: macos shell replace copy automator

我想替换特定文件,例如。 file.js位于不同的文件夹结构中,但始终位于另一个同名文件名为“core”的同一文件夹中。

示例:将“file.js”复制到文件夹的不同子文件夹中的所有“核心”文件夹

示例:

从:

x1 / file.js

为:

x / a / a1 / a3 / core /file.js

x / b / b1 / core / file.js

我在osx上尝试了automator的解决方案,但我没有设法存储核心文件夹的文件路径或将文件复制到路径变量。

有谁知道解决方案?

shell脚本或automator或任何其他自动化解决方案

1 个答案:

答案 0 :(得分:1)

这应该作为bash脚本执行,但首先在临时数据的副本上进行测试:

find . -name core -type d -execdir bash -c 'cd core && [ -f file.js ] && cp SOMENEWFILE .' \;

cp SOMENEWFILE .替换为pwd以测试并查看复制到的目录。