【问题标题】:How to copy and replace files in Apple Automator, while retaining folder structure?如何在 Apple Automator 中复制和替换文件,同时保留文件夹结构?
【发布时间】:2017-04-30 15:33:44
【问题描述】:

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

例如,从这个开始:

/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

我已经创建了以下 Automator 项目,但是文件都复制到目标文件夹的根目录。

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

【问题讨论】:

  • 看起来调用“sync -RI”可以解决这个问题。我正在继续探索。

标签: macos automator


【解决方案1】:

我找到了以下作品。

在 Automator 中添加“运行 AppleScript”动作,然后添加以下脚本:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 2022-10-15
    相关资源
    最近更新 更多