Renaming script using parent folder name as part of new file name

I have a folder for each client, all with subfolders. I will start with the easy case: I want to rename files to include the client parent folder name (which is the client name) and perhaps some other boilerplate. I assume I need to make a script for this. and I assume I need to assign the folder name to a variable, but I do not know how to do that. Or is there an easier way than doing it manually every time? Even a preset would be good enough it could put the folder name into the file name.

If you use the Rename dialog, click the drop-down arrow on the right end of the New name field. There are lots of useful things in there. In that menu, if you go to Name and Path, you'll see Parent folder. That drop-down feature works in all rename Modes, so you can use the Regular Expressions feature.

When you get it the way you like it, be sure to use the icon with the down-arrow on top of floppy disk (lol) so you can save the preset for future use. (The up-arrowed disk loads the highlighted preset.)

Thanks, DesertDwarf, I just came back to apologize after RTFM'ing. I never realized that drop down arrow did that. I guess I never checked. I think i assumed it just displayed some prior action. Guess I will save learning scripting for another day! Thanks for responding so fast. --Chris

Here's a rename preset that will append the parent folder name to the front of the file and separate it with a " - ":

Leading folder name.orp (223 Bytes)

To use this go into the advance rename dialog, click present management (floppy disk w/ down arrow) then import.

If you want to edit the output just change the new name field.

[parent] represents where the parent folder name will be placed
\1 represents the original filename

1 Like

Hey, thanks evernessince. Nice simple example to suck me into Regex! --Chris

RegEx isn't needed.

Mode: Standard Wildcard Rename
Old name: *
New name: {parent} - *

...is equivalent to:

Mode: Regular Expression
Old name: (.*)
New name: {parent} - \1

See these screenshots for comparison:

RegEx comes in handy when you want to break apart the names and either rearrange the parts or selectively use specific parts of the original name (or other fancy-schmancy stuff).

1 Like

Agreed. But it was a reminder about using RegEx when I do need to do something more involved. Got me to bookmark those pages of the manual. Just discovering that drop down list of codes, however, will probably serve most of my needs. Thanks. --Chris

Happy to help :slight_smile: