2012-03-11 120 views
1

我正在嘗試製作一個Applescript,它需要一個名稱列表並從中創建一組文件夾。然後將選定文件夾中的文件複製到每個新創建的文件夾中。將多個文件複製到新手appelscript中的文件夾

我有搜尋的答案,但不明白他們。所以,如果你可以善意地解釋什麼,爲什麼我應該改變代碼,這對我來說將是一次很好的學習經歷。

set destinationFolder to choose folder 
set {text returned:textReturned} to display dialog "enter folder names" default answer   return & return & return 
if textReturned is "" then return 
set folderWithFiles to (choose folder with prompt "Where are the files at?") 
repeat with aLine in (get paragraphs of textReturned) 
if contents of aLine is not "" then 
    do shell script "/bin/mkdir -p " & quoted form of (POSIX path of dest inationFolder & aLine) 
    set folderNew to aLine & ":" as alias 
    set dest to folderNew on destinationFolder -- as alias 
    tell application "Finder" 
     duplicate every file of folderWithFiles to dest 
    end tell 
end if 
end repeat 

在此先感謝 更新時間:發佈答案自己

+0

這是該計劃的所有沿。當我找到答案時,我不得不等待5個小時才能發佈答案。另有48個可以接受它。所以耐心的男孩。 – Runar 2012-03-11 21:33:52

+0

所以我最終從這個問題中學到了一些東西...... – adayzdone 2012-03-12 01:51:14

回答

1
從StefanK

得到幫助在macscripter.net

下面是完整的代碼:

set destinationFolder to choose folder 
set {text returned:textReturned} to display dialog "enter folder names" default answer return & return & return 
if textReturned is "" then return 
try 
    set theFiles to (choose file with prompt "Where are the files at?" with multiple selections allowed) 
end try 
repeat with aLine in (get paragraphs of textReturned) 
    if contents of aLine is not "" then 
     set newFolder to (destinationFolder as text) & aLine 
     do shell script "/bin/mkdir -p " & quoted form of POSIX path of newFolder 
     try 
      tell application "Finder" to duplicate theFiles to folder newFolder 
     end try 
end if 
end repeat 
相關問題