I was recently approached by one of my blog readers John Ott, to help out with a bit of a technical challenge he had. John used a fairly complicated filing system for keeping track of lots of documents, blue prints and photos for projects him and his team work on. This included many subfolders with deep subfolders following a strict naming convention. When John starts a project, he used to copy and paste his top-level folder, then work his way through all its subfolders updating the folder names with the new project code. John reached out to me to see if I could help out, so I put together this Bulk folder rename AppleScript which takes user input for source and destination folders and the latest project code, it then traverses the folders and their subfolder and updates the names as required.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
-- Apple Script to copy and rename a folder structure and its subfolders -- Author Mike Hudson (aka MikeSel - https://www.mikesel.info) tell application "Finder" set JobName to text returned of (display dialog "Please enter five digit code:" default answer "ST1234") set templateFolder to choose folder with prompt "Please Choose Template Folder" set fldName to name of templateFolder set newName to my replace_chars(fldName, "ST000", JobName) set destinationFolder to choose folder with prompt "Please Choose Destination Folder" set newFolder to duplicate templateFolder to destinationFolder set pro_folder to newFolder set all_pro_folders to every folder of pro_folder log all_pro_folders repeat with parent_folder in all_pro_folders log parent_folder set child_folders to every folder of parent_folder repeat with current_folder in child_folders set grandchildItems to every item of current_folder repeat with grandchildItem in grandchildItems set greatgrandchildItems to every item of grandchildItem repeat with greatgrandchildItem in greatgrandchildItems set fold_name to the name of greatgrandchildItem log (fold_name) set new_name to my replace_chars(fold_name, "ST000", JobName) set the name of greatgrandchildItem to new_name log (new_name) end repeat set fold_name to the name of grandchildItem log (fold_name) set new_name to my replace_chars(fold_name, "ST000", JobName) set the name of grandchildItem to new_name log (new_name) end repeat set fold_name to the name of current_folder log (fold_name) set new_name to my replace_chars(fold_name, "ST000", JobName) log (new_name) set the name of current_folder to new_name end repeat set fold_name to the name of parent_folder log (fold_name) set new_name to my replace_chars(fold_name, "ST000", JobName) log (new_name) set the name of parent_folder to new_name end repeat set pro_folder's name to newName end tell on replace_chars(this_text, search_string, replacement_string) set AppleScript's text item delimiters to the search_string set the item_list to every text item of this_text set AppleScript's text item delimiters to the replacement_string set this_text to the item_list as string set AppleScript's text item delimiters to "" return this_text end replace_chars |
You can download a zipped up copy of the above script by clicking
.If you’ve a project and you’d like to see if I can help, get in touch using my Contact Form.