Sequential number *inside* a filename

Hello, all.

I'm trying to put a sequential number inside a filename. I found a script, written by Leo, UniqueNumbers script and I'm studying it to change towards my needs. Leo's script put numbers, but not like I want to. If I did not misunderstood, his script has a fixed string before and after the numbers. But I need to keep the other half of the filename untouched, after the numbers. Like this:

(Before)
filename_oneThing.jpg
filename_otherThing.jpg

(After)
filename_001_oneThing.jpg
filename_002_otherThing.jpg

I was trying to use some code from PE5_InsertPosition_(beginning), written by Albator V. At the end of his script he uses the rest of the original name as FinFichier = Right (NomFichier, Len(NomFichier) - Position).

But I'm afraid I'm too newbie in VBasic that I cannot make such changes inside Leo's script to reaches my goal.
May you, guru guys, could give me a hand and teach the right way to put sequential numbers inside a filename?

Thx.

If you're not comfortable with scripting, did you know you don't really need a script to do this?
Just launch the Opus rename dialog, put it in advanced mode, and configure it like the screen grab below.


JohnZeman,

I'm so ashamed... :blush:

That's right! it solves my present problem. But what if I need to insert the numbers inside a filename without underscore?

Like this:
filenameWithoutUnderscore.jpg

And I want this:
filename_001_WithoutUnderscore.jpg

Yes, I know, you may say I always can FindAndReplace "filename" with "filename_[#]", but if the begining of the name is different?

I mean, I want to insert the sequential numbers at given position, keeping the rest untouched.

Thx.

If find and replace won't do it, using a regular expression very well may, but in order for that to work you need to establish a pattern in your file names to base the RegEx on.

For example to insert a number right after the 4th character in a file name regardless of what the first 4 characters are, you could do this:


Even with a script you still need to define some rules so to speak. In other words you have to know exactly what you want to do so you can tell the script (or the Opus rename dialog) what to do.

JohnZeman,

thank you very much for your prompt reply. Your suggestion solve my present problem and further ones. I saved that RegExp as my favorites.

Excellent!

:thumbsup: :thumbsup: :thumbsup:

@Admin

How to edit the post and put SOLVED?

Thx

See Why can't I edit my posts?.

Regards, AB