Applescript to add grandparent folder+parent folder prefix to filename <p>I have multiple folders with sub folders that have files in them that need to be labeled with their parent folder+grandparent folder name.</p> <p>i.e. Folder 1>Folder 2>File.jpg needs to be renamed to Folder_1_Folder_2_File.jpg</p> <p>I was able to find a script that somewhat does it, and have been trying to reverse engineer it, but am not having any luck. The script below presents two challenges, 1) It includes the entire path from the root directory, and two, it deletes the name of the file, therefore only allowing one file to be renamed before it errors out. I know that the problem is that the script is renaming the entire file, I just don't know how to proceed.</p> <pre><code>tell application "Finder" set a to every folder of (choose folder) repeat with aa in a set Base_Name to my MakeBase(aa as string) set all_files to (every file in aa) repeat with ff in all_files set ff's name to (Base_Name &amp; "." &amp; (ff's name extension)) end repeat end repeat end tell to MakeBase(txt) set astid to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" set new_Name_Raw to every text item of txt set AppleScript's text item delimiters to "_" set final_Name to every text item of new_Name_Raw as text set AppleScript's text item delimiters to astid return final_Name end MakeBase </code></pre> <p>Thank you!</p>