2014-02-25 30 views
1

我想測試,如果從文件夾路徑上的一個文件,在不同的文件夾使用該腳本存在:AppleScript的 - 如果文件在文件夾中不重複

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

http://stackoverflow.com/search?q=[applescript]duplicate+files – 2014-02-25 08:51:16

回答

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" 
+1

+1 ,但是我們是否應該擔心'man cp'對'-r'所說的話?歷史版本的cp實用程序有一個-r選項。該實現 支持該選項;然而,它的使用是強烈的不鼓勵,因爲它不正確地複製特殊文件,符號鏈接或fifo'。 – mklement0

相關問題