AppleScript - 在目录的每个文件夹和子文件夹中粘贴一个文件

AppleScript - Paste a file in every folder and sub folder of directory

我有一个包含子目录的目录。我想在每个文件夹中放置一个文件,而不使用 sudo 命令。我只想使用苹果脚本代码和终端命令,使用命令行:

do shell script ""


文件名为hello.png

我希望得到任何帮助! :) 谢谢大家!

复制现在已在主文件夹的所有子文件夹中完成(无论递归级别是什么。

下面的脚本可以满足您的需求:

set MyFile to choose file with prompt "Select file to be duplicated in every folder"
set MyFolder to choose folder with prompt "Select the folder in which you want to copy the file"

tell application "Finder"
set SubFolders to every folder of entire contents of MyFolder
repeat with aFolder in SubFolders
    duplicate MyFile to aFolder
end repeat
end tell

我假设您想将所选文件复制到所选文件夹的所有子文件夹中。然后,我没有添加...

的子文件夹的子文件夹的递归搜索

在这个脚本中,我只使用了 Applescript 命令。您可以用 do shell 脚本命令替换 "duplicate" 行(使用 shell 命令 'cp')。但是在这种情况下,脚本必须使用 posix 路径和引用形式...这比简单的 Finder 重复指令更复杂!