Rename based on first filename

Hi all,

I want to create a button that renames all selected files with a new name and number.

Example: I have...

my pic.jpg anotherOne 2012.jpg new bike.jpg
...and want to rename them to...

picture 1.jpg picture 2.jpg picture 3.jpg

In three dialogs this function asks for the new name (leaving the extension alone), the start and the step for numbering and works perfectly: :sunglasses:

Rename PATTERN ".*\.(.*)" TO "{Dlgstring|Name:} .\1" NUMBER {DlgstringS|Start:|1} BY {DlgstringS|Step:|1} REGEXP

However, I would like to use the name of the first selected file as a default for entering the new name. So I tried this:

Rename PATTERN ".*\.(.*)" TO "{DlgstringS|Name:|{file$|noext}} .\1" NUMBER {DlgstringS|Start:|1} BY {DlgstringS|Step:|1} REGEXP

At first, it seems to work as well, but then it opens the three dialogs for each of the selected files! :frowning:

How can I avoid that?
Thanks a lot,
MartO

Hi MartO,

I think this will do what you want?

@runonce:@set filename={dlgstringS|Rename to:|{file$|noext}} @runonce:@set startnum={dlgstringS|First Number Begings with:|1} @runonce:@set numby={dlgstringS|Incrementing By:|1} Rename PATTERN ".*\.(.*)" TO "{$filename} .\1" NUMBER {$startnum} BY {$numby} REGEXP @nodeselect

I think I'll keep this button for myself. Thanks for the idea :slight_smile:

[quote="ktbcrash"]Hi MartO,

I think this will do what you want?[/quote]

Perfect! :smiley: I hadn't come across @runonce yet.
By the way, in case you haven't noticed: If you enter "01" as the starting number, Rename uses leading zeros and produces 01, 02, ... 10, 11 instead of 1, 2, .. 10, 11.

Thanks a lot - and: You're welcome! :wink:
MartO

It might be worth sticking a [#] in the new filename (i.e. the TO argument) to explicitly say where the number should be inserted, otherwise existing numbers (if any) in the filename may be replaced.

I think it's more of the @set variable that did it. You can remove the @runonce: from each line and it still works. (Also added Leo's suggest for [#])

@set filename={dlgstringS|Rename to:|{file$|noext}} @set startnum={dlgstringS|First Number Begings with:|001} @set numby={dlgstringS|Incrementing By:|1} Rename PATTERN ".*\.(.*)" TO "{$filename} [#].\1" NUMBER {$startnum} BY {$numby} REGEXP @nodeselect
I'm not really sure what it all means. I just took some ideas from another button and it worked :astonished: (idk, I'm not a programmer). Leo didn't point out that @runonce: was wrong, so maybe it's ok to leave it. As long as it works, right? :slight_smile:

Yes, I prefer 001 but your sample showed 1 so I left it at that :slight_smile:

Runonce shouldn't be needed, but may be (or may have been in the past) in some cases to workaround some quirk. If it works without it then leave it off, but equally it shouldn't cause any problems either.