In an automator mishap, 315 folders got accidentally renamed incorrectly, and i am trying to salvage the situation. Each folder contains many sequential qt movie files with the same name followed by a space and a 2 digit number (ex: Mayor interview 01, Mayor interview 02, …). Now, I need to rename each parent folder to match the filename of its contents but without the space and number(" 01")
I have very basic knowledge of automator so this task is well out of my league. I would appreciate any help so I don’t have to spend the next 5hrs manually copying filenames and renaming folders manually.
The folder name is ideally consistent in that it mirrors the file names within the folder. There is always a xxxxx 01.mov contained in each folder. If there is a way to search for the file that end in “01.mov”, that could serve as the source for the folder name. Hope this is clear.
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
set baseFolder to choose folder
tell application "Finder"
set allFolders to folders of entire contents of baseFolder
repeat with oneFolder in allFolders
try
set firstFileName to name of (1st file of oneFolder whose name ends with "01.mov")
set newFolderName to (text items 1 thru -2 of firstFileName) as text
set name of contents of oneFolder to newFolderName
end try
end repeat
end tell
set AppleScript's text item delimiters to oldDelims