如何在保留文件夹结构的同时复制和替换Apple Automator中的文件?

时间:2015-12-08 19:53:36

标签: macos automator

我有两个具有相似子文件夹结构的文件夹。我需要将文件从一个文件复制到另一个文件,而不是将文件替换为目标文件夹中的任何现有文件,并保留子文件夹层次结构。

例如,从这开始:

/source_folder/stuff/sub_one/file1.txt
/source_folder/stuff/sub_one/file2.txt
/source_folder/stuff/sub_two/file3.txt

/destination_folder/stuff/sub_one/file1.txt
/destination_folder/stuff/sub_one/file9.txt
/destination_folder/stuff/sub_three/file4.txt

复制后:

/source_folder/stuff/sub_one/file1.txt
/source_folder/stuff/sub_one/file2.txt
/source_folder/stuff/sub_two/file3.txt

/destination_folder/stuff/sub_one/file1.txt (replaced by copy in source_folder)
/destination_folder/stuff/sub_one/file2.txt (added from copy in source_folder)
/destination_folder/stuff/sub_one/file9.txt
/destination_folder/stuff/sub_two/file3.txt (added from copy in source_folder)
/destination_folder/stuff/sub_three/file4.txt

我创建了以下Auotmator项目,但这些文件都被复制到目标文件夹的根目录。

enter image description here

有关如何在Apple Automator中完成此操作的任何建议吗?

1 个答案:

答案 0 :(得分:0)

我找到了以下作品。

添加"运行AppleScript"在Automator中执行操作,然后添加以下脚本:

on run {input, parameters}

    tell application "Finder"

        set source to choose folder with prompt "Choose source folder"
        set destination to choose folder with prompt "Choose destination folder"

        do shell script "rsync -rI " & POSIX path of source & space & POSIX path of destination

    end tell

    return input
end run