Sunday, January 21, 2018

#1 2003-06-29 01:34:09 pm

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Organize Files by File Type

This script will create SubFolders based on Extension type and then move the associated files (of a specified folder) into the newly created SubFolders.

OS version: OS X


tell application "Finder"
   set file_groups to {{"AVI", "avi"}, {"QuickTime", "mpe"}, {"QuickTime", "mpg"}, {"QuickTime", "mpeg"}, {"QuickTime", "mov"}, {"Images", "jpg"}, {"Images", "gif"}, {"Windows Media", "wmv"}, {"Windows Media", "asf"}, {"RealPlayer", "ram"}, {"RealPlayer", "rm"}, {"Documents", "txt"}, {"Documents", "doc"}, {"Documents", "pdf"}, {"Documents", "rtf"}}
   set the folder_name to {}
   set the file_type to {}
   set the chosen_folder to choose folder with prompt "Choose a folder to group"
   if chosen_folder is false then return "User Cancelled"
   repeat with i from 1 to the count of the file_groups
       copy item i of the file_groups to {folder_name, file_type}
       set selected_files to (every file of chosen_folder whose name extension contains file_type)
       if selected_files is not equal to {} then
           if not (exists folder folder_name of folder chosen_folder) then
               make new folder at folder chosen_folder with properties {name:folder_name}
           end if
       end if
       select (every file of chosen_folder whose name extension contains file_type)
           move the selection to folder folder_name of folder chosen_folder
       end try
   end repeat
end tell

One mans trash is another mans treasure

Filed under: Finder



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)