我正在尝试使用此脚本测试文件夹路径中的文件是否存在于其他文件夹中:
set middfilesECON211 to ("/Volumes/middfiles/Classes/Spring14/ECON0211B/HANDOUTS" as POSIX file)
set gDriveECON211 to ("/Users/paolob/Google Drive/Spring 2014/ECON 211/Handouts" as POSIX file)
tell application "Finder"
set foo to every file of folder middfilesECON211
repeat with i from 1 to (length of foo)
if not (exists (item i of foo) is in files of folder gDriveECON211) then
duplicate (item i of foo) to gDriveECON211
end if
end repeat
end tell
我在if not (exists) ...
条款中尝试了一些变体,但无济于事。
非常感谢任何帮助。谢谢!
答案 0 :(得分:1)
set dir1 to POSIX file "/tmp/a"
set dir2 to POSIX file "/tmp/b"
tell application "Finder"
repeat with f in (get items of folder dir1)
if not (exists file (name of f) of folder dir2) then
duplicate f to folder dir2 without replacing
end if
end repeat
end tell
您还可以使用cp -n
:
do shell script "cp -nR /tmp/a/ /tmp/b"
或rsync --ignore-existing
:
do shell script "rsync -r --ignore-existing /tmp/a/ /tmp/b"