File Applescript-如果文件位于文件夹don';不可复制

File Applescript-如果文件位于文件夹don';不可复制,file,if-statement,applescript,directory,File,If Statement,Applescript,Directory,我正在尝试使用以下脚本测试文件夹路径中的文件是否存在于其他文件夹中: 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 "Fin

我正在尝试使用以下脚本测试文件夹路径中的文件是否存在于其他文件夹中:

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)…
子句中的一系列变体,但没有效果

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--忽略现有的

do shell script "rsync -r --ignore-existing /tmp/a/ /tmp/b"

+1,但是我们应该担心
人cp
-r
的看法吗<代码>cp实用程序的历史版本有一个-r选项。这一实施支持这一选择;但是,强烈反对使用它,因为它不能正确复制特殊文件、符号链接或fifo。