Download RAR Expander
and drop the app into the Applications folder:
http://rarexpander.sourceforge.net/Downloads.html
Make sure to open RAR Expander
once before proceeding.
Now run the following 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
Workflow by script explained:
- Determine input folder (containing one or multiple RAR files).
- Determine output folder (empty folder).
- Extract the RAR archives within the input folder to the output folder.
- Loop through the files within the output folder.
- Only preserve the files with extensions mentioned in the extension list.
For Example, the input folder contains the following files:
Archive_Containing_FLV_File.rar
Archive_Containing_MP4_File.rar
Archive_Containing_PDF_File.rar
After running the script, the output folder only contains:
The_Extracted_FLV_File.flv
The_Extracted_MP4_File.mp4
The PDF file (The_Extracted_PDF_File.pdf
) is automatically deleted by the script.
Note: The script above is quickly written and can be optimized.