2012-10-04 107 views
0

我有一個包含大約500個選定文件名的文本文件(每個文件名都在它自己的行上),這個文件名來自拍攝超過3,000張照片的事件。我希望能夠找到文件夾中的所有圖像,複製它們,並將這些複製的文件移動到不同的文件夾中。使用AppleScript搜索/複製文件夾中的多個文件

這是我到目前爲止。現在,它只是複製3000倍的圖像的整個文件夾,並把它到目標文件夾,而不是單獨的文件..

文本文件:

_EPW0847.jpg 
_EPW0848.jpg 
_EPW0853.jpg 
etc....

的AppleScript:

set thePhotos to paragraphs of (read (choose file with prompt "Choose a text file")) 
set theSourceFolder to (choose folder with prompt "Choose source folder") as string 
set theDestination to (choose folder with prompt "Choose destination folder") 
repeat with theName in thePhotos 
    try 
     tell application "Finder" to duplicate alias (theSourceFolder & theName) to theDestination with replacing 
    end try 
end repeat 
tell application "Finder" 
    tell folder theDestination to set theCount1 to (count of items) as string 
end tell 
set theCount2 to (count of thePhotos) as string 
display dialog (theCount1 & " of " & theCount2 & " items copied to " & theDestination) buttons {"OK"}

任何幫助會很好。我不知道蘋果腳本,但我正在學習。謝謝!

回答

0

您近距離了!

set thePhotos to paragraphs of (read (choose file with prompt "Choose a text file")) 
set theSourceFolder to (choose folder with prompt "Choose source folder") 
set theDestination to (choose folder with prompt "Choose destination folder") 
set dupeList to {} 
repeat with theName in thePhotos 
    try 
     set end of dupeList to alias ((theSourceFolder as text) & theName) 
    end try 
end repeat 

tell application "Finder" to duplicate dupeList to theDestination with replacing 

set theCount1 to (count of dupeList) as text 
set theCount2 to (count of thePhotos) as text 
display dialog (theCount1 & " of " & theCount2 & " items copied to " & (theDestination as text)) buttons {"OK"} 

如果在文本文件中的空行,試試這個:

set thePhotos to paragraphs of (read (choose file with prompt "Choose a text file")) 
set theSourceFolder to (choose folder with prompt "Choose source folder") 
set theDestination to (choose folder with prompt "Choose destination folder") 
set dupeList to {} 

repeat with theName in thePhotos 
    try 
     if theName ≠ "" then 
      set end of dupeList to alias ((theSourceFolder as text) & theName) 
     end if 
    end try 
end repeat 
+0

嗯..它仍然複製整個文件夾。它是TXT文件的格式嗎?它應該是CSV格式嗎? – eliwedel

+0

嘗試編輯後的版本...... – adayzdone

+0

也沒有工作,但我找到了一個選項,它適用於我。我不得不改爲CSV文件,但我不介意:) – eliwedel

0
set fileContents to read (choose file with prompt "Choose a comma-delimited text file") 
set theText to result 
set AppleScript's text item delimiters to "," 
set theTextItems to text items of theText 
set AppleScript's text item delimiters to {""} 
theTextItems 
set theSourceFolder to (choose folder with prompt "Choose source folder") as string 
set theDestination to (choose folder with prompt "Choose destination folder") 
repeat with theEPSName in theTextItems 
    tell application "Finder" 
     set theEPSFile to theSourceFolder & theEPSName 
     move file theEPSFile to folder theDestination with replacing 
    end tell 
end repeat
相關問題