Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator Workflow Copying Files

I want to create an Automator workflow that copy items to a destination folder but ignores files that already exist in the destination. I begin having trouble at the "Copy Finder Items" action where the only options are to replace existing files or create duplicates in th destination folder?

Automator-OTHER, OS X Mountain Lion (10.8.2)

Posted on Feb 20, 2013 4:47 AM

Reply
Question marked as Best reply

Posted on Feb 21, 2013 5:48 PM

Hi Shane,


I sort of get what you're saying, but why would you be copying if you don't want to copy?


If you check the option "Replacing existing files" in the Copy Finder Items action, you don't lose anything - unless you have different files with the same name in different source folders.


If you only want to copy files whose names are different from the files in your destination folder, then you probably need a "Run AppleScript" action which will preview the names of the files in the destination folder, compare them with each file that you want to copy, and only copy files with unique/new names.

26 replies
Question marked as Best reply

Feb 21, 2013 5:48 PM in response to shanefanta

Hi Shane,


I sort of get what you're saying, but why would you be copying if you don't want to copy?


If you check the option "Replacing existing files" in the Copy Finder Items action, you don't lose anything - unless you have different files with the same name in different source folders.


If you only want to copy files whose names are different from the files in your destination folder, then you probably need a "Run AppleScript" action which will preview the names of the files in the destination folder, compare them with each file that you want to copy, and only copy files with unique/new names.

Feb 24, 2013 2:32 PM in response to HD

Thanks for the reply! I agree that the repalce exsiting files in would solve the problem, but the files that i am moving are large file (1gb or greater) and i was looking to speed up the process without having to overwrite these files!


I had a feeling that running an apple script would be the route that i need to go down, i just dont have any great experience with it!

Feb 24, 2013 2:54 PM in response to shanefanta

Ah, that makes sense. You can create an Automator workflow with a single Run AppleScript action, delete all the default text in the action and copy and paste in the following text:


tell application "Finder"

set source_folder to (choose folder with prompt "Choose the source folder:")

set target_folder to (choose folder with prompt "Choose the destination folder:")

if source_folder is not target_folder then


duplicate every file of source_foldertotarget_folder without replacing

else

display dialog "Choose different folders as source and target!" buttons {"OK"} default button 1 with icon stop

end if

end tell


The Automator window will look something like this:


User uploaded file


Hope this helps.

Feb 26, 2013 10:51 AM in response to shanefanta

My bad.


Try this script instead:


tell application "Finder"

set source_folder to (choose folder with prompt "Choose the source folder:")

set target_folder to (choose folder with prompt "Choose the destination folder:")

if source_folder is not target_folder then

set the_files to every file of source_folder

repeat with each_file in the_files

set file_name to name of each_file

if not (exists file file_name of target_folder) then


duplicateeach_filetotarget_folder

end if

end repeat

else

display dialog "Choose different folders as source and target!" buttons {"OK"} default button 1 with icon stop

end if

end tell


It does what the first one should have done - checks the name of each file against the files already in the source folder and only duplicates those which aren't already there.

Feb 26, 2013 1:57 PM in response to shanefanta

Not quite.


The way my script works is to create a list of all the files in the source folder. This has the variable name the_files.


The script loops through each of these files in turn, allocating the variable name of each_file to the next file in the list, and duplicating it only if a file with the same name doesn't exist in the target folder.


You're on the right lines if you want to filter the files by keywords in the name, but you still need to loop. Something like this could work. I've used your variable name this_file instead of my name each_file. It also checks for an existing file before duplication:


tell application "Finder"

set the_files to files of source_folder

repeat with this_file in the_files

set this_file_name to name of this_file

if this_file_name contains "keyword" then

if (not exists file this_file_name of target_folder) then

duplicate this_file to target_folder

end if

end if

end repeat

end tell


Hope this helps.

Mar 30, 2013 2:35 PM in response to HD

Hi HD-


I'm very new to Automator and Apple Script. I've looked into backup software, but nothing allows me the flexibility to choose multiple destinations and sources.


I need script that is similar to Shane.


I'm a photographer, and I want to make sure I have the most recent edits backed up, but not recopy multiple GB of data every time it backs up.


I want to create 5 separate Automations - each from a different source to a different destination - in order to back up Folders on my mac and various hard drives.


I would also like these actions to repeat hourly. To check for new items and replace only if the existing files, if they are NEWER.


Could you assist?


Thanks so much!

Jul 9, 2013 9:28 AM in response to kmkphoto

kmkphoto wrote:


Hi HD-


I'm very new to Automator and Apple Script. I've looked into backup software, but nothing allows me the flexibility to choose multiple destinations and sources.


I need script that is similar to Shane.


I'm a photographer, and I want to make sure I have the most recent edits backed up, but not recopy multiple GB of data every time it backs up.


I want to create 5 separate Automations - each from a different source to a different destination - in order to back up Folders on my mac and various hard drives.


I would also like these actions to repeat hourly. To check for new items and replace only if the existing files, if they are NEWER.


Could you assist?


Thanks so much!

(4 months later)

Why not simply use Time Machine?

Automator Workflow Copying Files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.