Rename button with title dialog, parent folders, and numbers

I would like to create a button to rename files. The directory structure is like this:

Parent Folder 2 (with information in parenthesis)_Suffix/Parent Folder/MyFile.png

I'd like a dialog to add a custom title followed by a static " by ". Then I want to include "Parent Folder 2" but remove everything after it. Then I want to include the Parent Folder in parenthesis. I'd also like to be able to select multiple files at once to use the same custom title, and number them. The final filenames would look like this:

Custom title by Parent Folder 2 (Parent Folder)_01.png
Custom title by Parent Folder 2 (Parent Folder)_02.png
Custom title by Parent Folder 2 (Parent Folder)_03.png

I managed to get a rename button that can rename single files with this structure, but when I select more than one file I get a "file already exists" error. I found a button Leo made a few years ago that can take a custom name and number multiple selected files, but I don't know how to combine it with extracting the parent folder names. Any help getting this to work would be greatly appreciated.

Try this quick fix:

image

That works if I'm doing it from the rename dialog, but not if I'm doing it from a button directly in the lister. It also doesn't rename them like:

Custom title by Parent Folder 2 (Parent Folder)_01.png
Custom title by Parent Folder 2 (Parent Folder)_02.png
Custom title by Parent Folder 2 (Parent Folder)_03.png

Instead it numbers them like this:

Custom title by Parent Folder 2 (Parent Folder).png
Custom title by Parent Folder 2 (Parent Folder)(1).png
Custom title by Parent Folder 2 (Parent Folder)(2).png

You can customize the numbering scheme via

image

Thanks, but the rename numbering options aren't applying to my button. I still get the error.

How did you insert [#]?

Those options are in the rename dialog. I'm not renaming files from this location. I'm renaming files directly in the lister with a button using the Rename internal command.

Leo made a button that does part of what I want to do. It looks like this:

<?xml version="1.0"?>
<button display="both" label_pos="right">
	<label>Rename Explorer Style</label>
	<icon1>#duplicate</icon1>
	<function type="normal">
		<instruction>Rename NUMBER=001 REGEXP PATTERN=&quot;^(.*)(\.[^.]+)DISCOURSE_PLACEHOLDER_1quot; TO=&quot;{dlgstring|Enter base name}[#]\2&quot;</instruction>
	</function>
</button>

This already brings up the custom title dialog and numbers the files appropriately. I would like to edit this button so that it can match the format I have in the original post with the formatted parent folder names.

I know I can use {parent} and {parent2} in this to get the parent folder names, and I know I can use the regular expression \(.*$ to remove everything after the first parenthesis. Everything works if I do one step at a time. I just can't figure out how to put it all together in a single command.

You'll probably need to use a Rename Script to do everything in a single pass, since you need to apply changes to not just the filename itself but the parent folder names that are being inserted into it.

Okay. If I didn't need to modify the Parent 2 folder, what would be the proper way to insert the parent folders into the command?

{parent1} and {parent2} work with the command's TO argument the same as in the dialog's New Name field. At least, they should as far as I know.

Leo, you're right. It wasn't working when I tried it before, but I must have accidentally added or removed something else.

I got this to work in a button without a script by compromising on the filename. I put the parent folder in brackets instead of parentheses then added a step to remove the extra information from parent folder 2.

The final output looks like this:

Custom title by Parent Folder 2 [Parent Folder]_01.png

The button content looks like this:

Rename NUMBER=01 REGEXP PATTERN="^(.*)(\.[^.]+)$" TO="{dlgstring|Enter base name} by {parent2} [{parent}]_[#]\2"
Rename REGEXP PATTERN="(.*)( \(.*\)...)(.*)#" TO="\1\3"

It may not be the most elegant solution (I'm still figuring out how to do regular expressions), but it does exactly what I want so I'm happy with it.

Thanks to both of you for responding.

1 Like