2011-08-08 26 views
0

我從來沒有碰過蘋果腳本,我只需要一個小腳本,但不知道從哪裏開始。Applescript Noob,unrar .rar文件並移動包含文件

所有我想要做的就是運行在文件夾操作腳本..

當我把一個一個RAR文件的文件夾中,以基本耗盡。它需要unrar然後移動文件,只有當它是一個電影文件到另一個文件夾?

這可能嗎?

感謝

+0

我認爲這個問題可能是一個很好的起點:http://stackoverflow.com/questions/3896175/applescript-processing-files-in-folders-recursively – Asmus

回答

1

下載RAR Expander和應用程序拖放到應用程序文件夾: http://rarexpander.sourceforge.net/Downloads.html
確保在繼續之前打開RAR Expander一次。

現在運行下面的AppleScript:

property extensionList : {"mp4", "flv"} 

tell application "Finder" 

    set the sourceFolder to choose folder with prompt "Select Input Folder" 
    set the outputFolder to choose folder with prompt "Select Output Folder" 

    set inputFiles to every file of the sourceFolder whose name extension is "rar" 

    repeat with i from 1 to the count of inputFiles 
     set theArchive to POSIX path of ((item i of inputFiles) as string) 
     tell application "RAR Expander" 
      expand theArchive to POSIX path of outputFolder 
     end tell 
    end repeat 

    set extractedFiles to every file of the outputFolder 

    repeat with i from 1 to the count of extractedFiles 
     if (the name extension of the (item i of extractedFiles) is not in the extensionList) then 
      do shell script "rm -rf " & quoted form of (POSIX path of ((item i of extractedFiles) as string)) 
     end if 
    end repeat 

end tell 

工作流由腳本解釋:

  • 確定(包含一個或多個RAR文件)輸入的文件夾。
  • 確定輸出文件夾(空文件夾)。
  • 將輸入文件夾中的RAR存檔提取到輸出文件夾。
  • 循環輸出文件夾內的文件。
  • 只保留擴展名列表中提及的擴展名的文件。

對於實施例中,輸入文件夾包含以下文件:

Archive_Containing_FLV_File.rar 
Archive_Containing_MP4_File.rar 
Archive_Containing_PDF_File.rar 

運行腳本後,將輸出文件夾僅包含:

The_Extracted_FLV_File.flv 
The_Extracted_MP4_File.mp4 

PDF文件(The_Extracted_PDF_File.pdf)是自動被腳本刪除。

注意:上面的腳本快速寫入並且可以優化。