(There is a typo in the title. It should be: “Merging two folders in Mojave”)
Dear all,
I have 2 folders with different set of files. I would like to synch them, in a way that at the end the 2 folders mirror each other.
The best I got is to:
set src to (choose folder with prompt "Select the source directory")
set dst to (choose folder with prompt "Select the destination directory/disk")
set a to quoted form of POSIX path of src
set b to quoted form of POSIX path of dst
-- do shell script "rsync -a " & quoted form of POSIX path of src & space & quoted form of POSIX path of dst
do shell script "rsync -a " & a & space & b
do shell script "rsync -a " & b & space & a
Is there any better way to do this, such as comparing modification date etc…
Thanks
ldicroce. I don’t know a better way to do what you want, but, just for practice, I decided to do this with Finder. As you know, the Finder is slow while rsync is fast. Also, the rsync command with the -a option is recursive, which my script is not. So, your current solution might be best.
set src to (choose folder with prompt "Select the source directory")
set dst to (choose folder with prompt "Select the destination directory/disk")
tell application "Finder"
set srcFiles to files in folder src as alias list
set dstFiles to files in folder dst as alias list
set srcNames to {}
repeat with i from 1 to (count srcFiles)
set the end of srcNames to the name of (item i of srcFiles)
end repeat
set dstNames to {}
repeat with i from 1 to (count dstFiles)
set the end of dstNames to the name of (item i of dstFiles)
end repeat
end tell
set srcUnique to {}
repeat with i from 1 to (count srcNames)
if (item i of srcNames) is not in dstNames then
set the end of srcUnique to (item i of srcFiles)
end if
end repeat
set dstUnique to {}
repeat with i from 1 to (count dstNames)
if (item i of dstNames) is not in srcNames then
set the end of dstUnique to (item i of dstFiles)
end if
end repeat
tell application "Finder"
duplicate srcUnique to dst
duplicate dstUnique to src
end tell
Thanks peavine.
You script is interesting also because can be adapted to include the modifications date as parameter to choose “similar” files among the 2 folders, which I don’t know how to implement with the rsync command.