I have a drive with number sequential job folders that I want to duplicate onto another volume. Here’s the script I’ve got so far trying to copy FOLDERS (containing files) to another folder.
For a sample test I have 2 folders on the desktop : “Source” and “Target”.
Target has folders numbered 1 to 9, Source has folders numbered 10 to 14. The objective being to get the script to copy the folders (and contents) that don’t exist in the Target folder from the Source folder.
set TargetFldr to (choose folder with prompt "Where is the target folder?")
set SourceFldr to (choose folder with prompt "Where is the source folder?")
tell application "Finder"
set f1Files to name of every folder of folder SourceFldr
set f2Files to name of every folder of folder TargetFldr
repeat with anItem in f1Files
if anItem is not in f2Files then
duplicate anItem to TargetFldr with replacing
end if
end repeat
end tell
Currently returning error:
Finder got at error: Can’t set alias “Mac:Users:Matt:Desktop:Target:” to item 1 of {“10”,“11”, “12”,“13”,“14”}.
Is the syntax correct for copying folders? (Lifted from another post)
the argument of folder is a path string, but you have an alias.
Use either
set TargetFldr to (choose folder with prompt "Where is the target folder?") as Unicode text
.
tell application "Finder"
.
set f2Files to name of every folder of folder TargetFldr
or
set TargetFldr to (choose folder with prompt "Where is the target folder?")
.
tell application "Finder"
.
set f2Files to name of every folder of TargetFldr
I cant seem to get this script to work properly, I see the second reply but I cant see how it is different, I keep getting the error “Can’t get folder…” is it a permissions thing?
More along these lines – you can’t duplicate a file by name – it must be by reference to it.
set TargetFldr to (choose folder with prompt "Where is the target folder?")
set SourceFldr to (choose folder with prompt "Where is the source folder?")
tell application "Finder"
set f1Files to every folder of folder SourceFldr
set f2Files to every folder of folder TargetFldr
set f2Names to name of every folder of folder targetfolder
repeat with k from 1 to count f1Files
if name of item k of f1Files is not in f2Names then
duplicate item k of f1Files to TargetFldr
end if
end repeat
end tell