Created
July 14, 2015 16:36
-
-
Save MikeSel/f38bc8eb4506a09c2e31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment