Apple Intelligence is now available on iPhone, iPad, and Mac!

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Rename files based on folder structure

Couldn't find this, but if this has already been answered, please point me to the right post.

I would like to rename pictures in a folder called "My Name". The pictures are currently named "1_09" or something similar, and I would like to append "My Name" before the numeric label. The end result would be a file called "My Name 1_09". This would have to be done recursevily on the folder structure of a directory that I choose.

Can it be done?

2x2.0 G5, Mac OS X (10.4.3)

Posted on Dec 19, 2005 9:50 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 19, 2005 2:35 PM

Should work with
Get Selected Finder Items
Get Folder Contents
Rename Finder Items (Don't Add Copy) [Add Text] (you may want to check the Show action when Run on this action to pick different names for images

Save As Plugin for Finder

Pick the folder you want, Ctrl-click, and select the plugin under Automator
10 replies
Question marked as Top-ranking reply

Dec 19, 2005 2:35 PM in response to Marcelo LaFleur

Should work with
Get Selected Finder Items
Get Folder Contents
Rename Finder Items (Don't Add Copy) [Add Text] (you may want to check the Show action when Run on this action to pick different names for images

Save As Plugin for Finder

Pick the folder you want, Ctrl-click, and select the plugin under Automator

Dec 19, 2005 4:45 PM in response to Mike-N-nahyunil

Got me started, but now I have this very cryptic error message when I try to run/save the action:

----------------------------------
Can't set |textInput| of {|numberSeparator|:0, |renameItems|:0, |defaultName|:"", |datePlacement|:0, |insertionPosition|:1, |dateFormat|:"0", |startingNumber|:1, |nameDateSeparator|:0, |ignoreCase|:true, |useLeadingZeros|:false, |minimumCount|:"2", |includeExtensions|:false, |replaceWithText|:"", |dateToUse|:0, |textToFind|:"", |caseIndicator|:0, |dateSeparator|:"0", |numberLocation|:0, |renameType|:1} to some object. (-10006)
----------------------------------

Dec 21, 2005 5:04 PM in response to Mike-N-nahyunil

It works if I type in the text to be added. But I can't seem to have it use the name of the selected folder. I think I'm making a silly mistake.

Workflow:

1-Get Selected Finder Items
2-Get Folder Contents (repeat for each subfolder found)
3-Rename Finder Items [add text] [blank text box]

This won't work unless I enter something in the text box. But how do I get Automator to use the Selected Finder Items result there?

Dec 21, 2005 10:05 PM in response to Marcelo LaFleur

It won't.

There may be a way to do it in AppleScript but Automator does things step-by-step and doesn't really hold on to the filenames or attributes from prior actions.

For the most part, figure that each action performs it's task then sends it's output onto the next action and finishes. There is no defining variables to be recalled later on.
With Show Action When Run selected for the Rename action, you can enter different names whenever you run the workflow.

Dec 22, 2005 8:54 AM in response to Marcelo LaFleur

This requires a recursive script, which could be wrapped in an Automator "Run AppleScript" action if you wanted to, but will also run from Script Editor.



set the_folder to (choose folder)
rename filesinside (the_folder)

on rename filesinside (next_folder)
tell application "Finder"
set folder_name to name of next_folder & " "
set folder_contents to every item of next_folder
repeat with each_item in folder_contents
if kind of each_item is "folder" then
my rename filesinside (each_item)
else
set name of each_item to folder_name & " " & name of each_item
end if
end repeat
end tell
end rename filesinside

I strongly suggest that you test this on a backup folder structure before you use it with important files.

The script could also be re-written as a droplet if required.

Happy Christmas!

H

Message was edited by: HD

Rename files based on folder structure

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.