简体   繁体   English

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

[英]How to copy and replace files in Apple Automator, while retaining folder structure?

I have two folders that have similar sub-folder structures. 我有两个文件夹具有相似的子文件夹结构。 I need to copy, not sync, the files from one in to the other, replace any existing files if they are present in the destination folder, and keep the sub-folder hierarchy. 我需要将文件从一个文件复制到另一个文件,而不是进行同步,如果目标文件夹中存在文件,请替换它们,并保留子文件夹的层次结构。

For example, starting with this: 例如,从此开始:

/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

After copying: 复制后:

/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

I've created the following Auotmator project, but the files are all copied to the root of the destination folder. 我创建了以下Auotmator项目,但是文件全部复制到了目标文件夹的根目录。

在此处输入图片说明

Any recommendations on how to accomplish this in Apple Automator? 关于如何在Apple Automator中完成此操作的任何建议?

I found the following works. 我发现以下作品。

Add a "Run AppleScript" action in Automator, then add the following script: 在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在文件夹结构中批量查找并用automator替换为其他文件 - Batch find in folder structure and replace with other file with automator 在保留文件夹结构的同时将html和css文件复制到dist - copy html and css files to dist while maintaining the folder structure 复制文件,同时保留mac中的目录结构 - copy files while preserving directory structure in mac 使用Automator复制文件,执行Cordova无法正常工作 - Using Automator to copy files, execute Cordova not working Automator服务,bash脚本:获取文件夹文件 - Automator service, bash script: get folder files Apple Automator处理CSV文件并创建新文件 - Apple Automator process csv files and create new files 如何使用 Automator 和 Applescript 根据日历事件中的特定文本将文件/文件夹批量移动到指定文件夹,MacOS - How to use Automator and Applescript to batch move files/folders to a specified folder based on specific text in Calendar Events, MacOS 相当于 MacOs 上的 robocopy - 复制完整的文件夹结构但包含空文件 - Equivalent to robocopy on MacOs - Copy full folder structure but with empty files 如何在 Automator 中获取 Shell 脚本的文件夹名称? - How to get name of folder for Shell Script in Automator? Mac Automator App:如何设置文件夹 - Mac Automator App: How to Set Folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM