Hi,
zezzerinsnow wrote:
I like the script to only duplicates those files who has been changede, or in other words the files who is different from the files on the backupfolder . But How to I do that?
First suggestion : rsync does this easily.
---------------------------------------------
set source to "/Users/Falentin/Documents"
set destFolder to "/Volumes/64 GB"
do shell script "/usr/bin/rsync -a " & (quoted form of source) & " " & (quoted form of destFolder)
-----------------------------------------------------
-- or you can use : do shell script "/usr/bin/rsync -a --delete-after " & (quoted form of source) & " " & (quoted form of destFolder)
The --delete-after option : rsync delete any items on the "/Volumes/64 GB" that aren’t on the Documents folder.
Important : the deleted items will be deleted permanently on the disk (not moved to the trash).
Second suggestions : Finder script is about three times slower than rsync.
---------------------------------------------
propertydeleteFilesOnDest : false -- set it to true to move any items on the destination folder to the trash that aren’t on the source folder
set source to (POSIX file "/Users/Falentin/Documents") as alias
set destFolder to ((POSIX file "/Volumes/64 GB") as alias)
mysyncFiles(source, destFolder)
onsyncFiles(tDir, dest)
script o
property L : {}
endscript
set itemsToCopy to {}
set dest to dest as string
tell application "Finder"
set o's L to files of tDir
repeat with i from 1 to (count o's L)
set f to item i of o's L
set destFile to (dest & name of f)
ifnot (existsfiledestFile) or (modification dateoff) > (modification dateoffiledestFile) then
set end of itemsToCopy to contents of f
end if
end repeat
repeat with f in (get folders of tDir)
set destF to dest & name of f
if (exists folder destF) then
my syncFiles(f as alias, destF as alias)
else
set end of itemsToCopy to contents of f
end if
end repeat
with timeout of 0 seconds
if itemsToCopy is not {} then duplicate itemsToCopy to dest with replacing
ifdeleteFilesOnDestthenmydeleteItems(tDir, destasalias)
end timeout
end tell
return ""
endsyncFiles
ondeleteItems(dir1, dest)
script ob
property L1 : {}
property L2 : {}
property L3 : {}
endscript
set ob's L1 to list folder dir1
set ob's L2 to list folder dest
set dest to dest as string
try
considering case
repeat with i from 1 to count (ob's L1)
set x to (ob's L2)'s item i
if x is not in ob's L1 then set end of ob's L3 to (dest & x) as alias
end repeat
endconsidering
if ob's L3 is not {} then tell application "Finder" to delete (ob's L3) -- move items to the trash
end try
enddeleteItems
---------------------------------------------