2016-03-09 58 views
0

基於列表或電子表格將文件放置到文件夾結構中是否有合理的簡單方法?基於單獨的列表將文件置於空文件結構中?

假設,例如,我有100個不同的動物圖像;分類的空文件夾結構 - 包含5個不同Family文件夾的Kingdom文件夾,每個文件夾包含5個Species文件夾;以及每個文件名及其相應的王國,家庭和物種的電子表格。我該如何編寫一些applescript或告訴automator來解釋電子表格中的信息,以便將每個圖像移動或複製到電子表格中指定的目錄?

我發現很多很好的方法將東西放置在特定的目錄中,但在使用單獨的列表來指定文件的目的地方面並不多。

感謝, 鋁

回答

0

最簡單的方法是將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 
+0

這工作就像一個魅力!非常感謝解決方案。 –

相關問題