最簡單的方法是將Excel列表保存到文本/製表符文件。然後腳本可以讀取該文件。
在下面的腳本中,我假設文本文件始終有3列文件名,系列文件夾名稱和物種文件夾名稱。
腳本首先詢問源文件夾(所有圖像都在哪裏),然後是'王國'文件夾(子文件夾和圖像將在哪裏),最後是文本文件(來自Excel)。
然後腳本循環到文本文件的每一行,並將文件移動到相關文件夾。如果子文件夾系列或物種不存在,則腳本在移動圖像之前創建它們。 如果文本文件的行不包含3個值,則會跳過該行。
我把很多意見,讓你調整如果需要的話:
set Source to (choose folder with prompt "Select images folder") as text
set Kingdom to (choose folder with prompt "Select destination folder") as text
set Ftext to choose file with prompt "Select text file containing naes & folder paths"
-- file format must be : FileName <tab> FamilyFolder <tab> SpeciesFolder <return>
set FContent to read Ftext
set allLines to every paragraph of FContent
repeat with aline in allLines
set AppleScript's text item delimiters to {ASCII character 9} -- use tab to split columns
set T to every text item of aline
if (count of text items of T) = 3 then -- valid line
set FName to text item 1 of T
set Family to text item 2 of T
set Species to text item 3 of T
tell application "Finder"
try
-- check if file Fname in Source folder exists
if not (exists file (Source & FName)) then
display alert "the file " & FName & " does not exist in source folder."
return
end if
-- check if folder Family in Kingdom folder exists
if not (exists folder Family in folder Kingdom) then
make new folder in folder Kingdom with properties {name:Family}
end if
-- check if folder Species in Family folder exists
if not (exists folder Family in folder Family of folder Kingdom) then
make new folder in folder Family of folder Kingdom with properties {name:Species}
end if
-- then move FName from Source to Kingdom/Family/Species
move file (Source & FName) to folder Species of folder Family of folder Kingdom
end try
end tell
end if
end repeat
這工作就像一個魅力!非常感謝解決方案。 –