2012-10-04 79 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
相关问题