Synching NAS to Folder on Local Machine
I am using applescript to duplicate files, replacing if a change, from one folder to another. It isn't deleting any extra remaining files/folder on the local side when done. Am I missing something?
property deleteFilesOnDest : 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 "/Volumes/Worship/Service Media") as alias
set destFolder to ((POSIX file "/Users/hitech/Desktop/TEST") as alias)
my syncFiles(source, destFolder)
on syncFiles(tDir, dest)
script o
property L : {}
end script
set itemsToCopy to {}
set dest to dest as string
tell application "Finder"
set o'sL to files of tDir
repeat with i from 1 to (counto'sL)
set f to itemi of o'sL
set destFile to (dest & name of f)
if not (existsfiledestFile) or (modification date of f) > (modification date of filedestFile) 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 (existsfolderdestF) 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 duplicateitemsToCopytodest with replacing
if deleteFilesOnDest then my deleteItems(tDir, dest as alias)
end timeout
end tell
return ""
end syncFiles
on deleteItems(dir1, dest)
script ob
property L1 : {}
property L2 : {}
property L3 : {}
end script
set ob'sL1 to list folderdir1
set ob'sL2 to list folderdest
set dest to dest as string
try
considering case
repeat with i from 1 to count (ob'sL1)
set x to (ob'sL2)'s itemi
if x is not in ob'sL1 then set end of ob'sL3 to (dest & x) as alias
end repeat
end considering
if ob'sL3 is not {} then tell application "Finder" to delete (ob'sL3) -- move items to the trash
end try
end deleteItems