Thursday, August 11, 2022

#1 2022-07-31 12:37:49 pm

From:: Greece
Registered: 2019-03-03
Posts: 2443

Batch Change File Extensions of Chosen Folder(s)


-- script: Batch change file Extensions of chosen folder(s), and (optionally) of its subfolders
-- written: by me, right now
-- you can choose multiple folders as well

property pathList : {}
property fromExtension : "txt" -- set here the "from" extension
property toExtension : "csv" -- set here the "to" extension
property processSubfolders : false -- set to true to process subfolders as well

set aFolders to choose folder with multiple selections allowed
repeat with aFolder in aFolders
   tell application "System Events" to set end of pathList to POSIX path of aFolder
   if processSubfolders then my get_All_Folders_of_Folder(aFolder)
end repeat

repeat with folderPath in pathList
   set folderPath to quoted form of folderPath
   try -- requred to avoid processing empty lists in the "for file in" repeat loop
       do shell script "cd " & folderPath & "; for file in *." & fromExtension & "; do mv $file `echo $file | sed 's/\\(.*\\.\\)" & fromExtension & "/\\1" & toExtension & "/'` ; done"
   end try
end repeat

----------------------------- Recursive Handler -----------------------------------
on get_All_Folders_of_Folder(aFolder)
   tell application "System Events"
       set foldersList to folders of aFolder
       if foldersList is {} then
           set end of pathList to (POSIX path of aFolder)
           repeat with aFolder in foldersList
               my get_All_Folders_of_Folder(aFolder)
           end repeat
       end if
   end tell
end get_All_Folders_of_Folder

Last edited by KniazidisR (2022-08-01 08:45:11 am)

Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)