Inserting characters at certain position?

Following code removes a number of chars from the front position:

Rename REGEXP PATTERN ".(.+)(..*)#{dlgstring|Number}" TO "\1\2" AUTORENAME

Some user from the other forums likes to know, how he can insert some characters in the specified position instead of replacing them in that
string. So he has for example the file name "exampleNumberOne", gives the string, which is to be inserted of "New" & position "8",
resulting in the new name "exampleNewNumberOne".

Well in its simplest form all you have to do is this:

Thx John, but this uses a fixed position & a fixed inserted word, while he´d like to give the position & the string individually. So somehow the "{dlgstring|Number}"
part has to be included. :confused:

You're making work on this one abr! :laughing:

After thinking more about this, I came to the conclusion the best way to do this would be with a RegEx VBScript. And I almost had such a script written but I hit a wall when I couldn't find a way for Opus rename VBScript to present a dialog box for user input. My normal means of doing so with an input box or user dialog do not seem to work. So I had to dump that idea and went back to a standard Opus button rename.

The following is rather crude as you have to enter one . for each character from the left side you want but it does seem to work. For example if you want to insert some text after the 3rd character, you would enter ... at the prompt. The second prompt is for you to enter the text you want to insert.

[code]@set X = ({dlgstring|Enter one . for each character from left (default is 3)|...})
@set Word = {dlgstring|Enter Text to insert|Some Text}

Rename REGEXP PATTERN "{$X}(.*)" TO "\1{$Word}\2"[/code]

I had a similar idea here John, but it has a small problem.
My idea was to count the characters to the left of the file extension and then rename the file in two steps.

@set Num = ({dlgstring|Enter the number of characters from right not including extension characters (default is 5)|5}) @set Word = {dlgstring|Enter Text to insert|Some Text} Rename REGEXP PATTERN "(.*)(\..*)" TO "\1{$Word}\2" Rename REGEXP PATTERN "(.*)(.+)({$Word})(.*)(\..*)#{$Num}" TO "\1{$Word}\2\4\5"
The first rename line works and inserts $Word just before the file extension.
The second rename line is not working at all when I use the variable $Num,
but it DOES work if I hard code a digit in after the '#' and hence ignore the value of $Num.

John, & Scred, thank you! I forwarded your codes. :laughing:

@JohnZeman:
Your Button works very good though the dots are not the elegant way.
But it ignores spaces at the beginning and end of entered text. So entering " Some Text " wil only insert "Some Text".
Perhaps this can be improved.

Hmm, you're right and I don't know what I can do about it for it seems Opus trims leading or trailing spaces when setting the value of a variable. This seems like a bug to me, but perhaps it's not. I'll do a bit more testing and if it still looks like a bug, I'll submit a bug report on it.

@JohnZeman:

Hi John!
I posted your Code at the german Forum and a Member there (joerg765) found a very simple solution that really works with Spaces:

Rename REGEXP PATTERN "({dlgstring|Enter one . for each character from left})(.*)" TO "\1{dlgstring|Enter Text to insert:}\2"

Does anybody know how to translate "number" to "number of dots" to give it the finishing Touch...?

Yes, that certainly solves it. :smiley:
I got so involved in trying to figure out why the leading/trailing spaces were being trimmed when assigned as a value to a variable, that it didn't occur to me to rewrite the command to not use variables at all.

I'm afraid I don't understand your last question about translating number to number of dots.

@JohnZeman:

What I meant with this is to get rid of the "Enter one . for each character from left" by typing just a number.
In the code the number must somehow be changed (=translated) to dots (e.g. "3" to "...").

Perhaps not a common phrase in english. In german it makes sense to say "Eine Zahl in eine Anzahl Punkte übersetzen" in this context.

A slight variation of the original (very neat) solution can be used to rename by adding a prefix..

Rename REGEXP PATTERN "()(.*)" TO "\1{dlgstring|Enter Text to insert:}\2"

I have created a 3-button rename with this command for prefix, and the original command for inserting characters in the middle. All that's missing is a command to add a suffix and I have a feeling I have seen that recently somewhere in these forums.

Regards, AB

I think you may need to use a rename script for that.

Here's one which takes some numeric inputs and might be a good starting point (even though it doesn't actually rename anything, it'll show you how to get the number into the script, and after that it'd be a standard rename script which there are a bunch of examples of):

Create Multiple Numbered Folders

This is why I first tried to solve this problem with a VBScript because you can do that with a script. But I had to give that idea up when I couldn't find a way to have a user dialog box pop up for input.

Hey thanks for that link Leo, I looked last night but missed that particular one... :exclamation: I'll take a peek at it in depth later on. :smiley:

Subsequently found this which seems to do the trick...

Rename REGEXP PATTERN "(.*)(.[^.]+)$" TO "\1{dlgstring|Enter suffix to insert:}\2"

Regards, AB

Joerg765 from the german Forum did it again:

Just by moving things round a little bit and using a temporary Name he found this tricky solution:

Insert Charcters BEHIND given Position:

@set X = {dlgstring|Insert behind Position Number:} Rename REGEXP PATTERN "(.)(.+)#{$X}" TO "\2\1" AUTORENAME Rename PATTERN "*" TO "TEMPNAME*" AUTORENAME Select TEMPNAME* Rename REGEXP PATTERN "(.+)(.)#{$X}" TO "\2\1" AUTORENAME Rename FINDREP PATTERN "TEMPNAME" TO "{dlgstring|Insert:}" AUTORENAME @NODESELECT

This one deletes characters BEHIND given Position:@set X = {dlgstring|Delete behind Position Number:} Rename REGEXP PATTERN "(.)(.+)#{$X}" TO "\2\1" AUTORENAME Rename PATTERN "*" TO "TEMPNAME*" AUTORENAME Select TEMPNAME* Rename REGEXP PATTERN "(........).(.+)#{dlgstring|Number of Charcters to Remove:}" TO "\1\2" AUTORENAME Rename PATTERN "*" TO "TEMPNAME*" AUTORENAME Select TEMPNAME* Rename REGEXP PATTERN "(.+)(.)#{$X}" TO "\2\1" AUTORENAME Rename FINDREP PATTERN "TEMPNAME" TO "\~" AUTORENAME @NODESELECT

...and here's a Variation of the first one, counting Characters from End of Filename and inserting BEFORE given Number:

@set X = {dlgstring|Insert before Position Number (counting from end of Name):} Rename TYPE=files REGEXP PATTERN "(.+)(.)(\..*)#{$X}" TO "\2\1\3" AUTORENAME Rename TYPE=dirs REGEXP PATTERN "(.+)(.)#{$X}" TO "\2\1" AUTORENAME Rename TYPE=files PATTERN "*.*" TO "*TEMPNAME.*" AUTORENAME Rename TYPE=dirs Pattern "*" TO "*TEMPNAME" AUTORENAME Select *TEMPNAME Rename TYPE=files REGEXP PATTERN "(.)(.+)(\..*)#{$X}" TO "\2\1\3" AUTORENAME Rename TYPE=dirs REGEXP PATTERN "(.)(.+)#{$X}" TO "\2\1" AUTORENAME Rename FINDREP PATTERN "TEMPNAME" TO "{dlgstring|Insert:}" AUTORENAME @NODESELECT

For me they are all fully working. Regards and many Thanks to Joerg765!

This would be so much easier if the following technique worked..

@set 0=
@set 1 = .
@set 2 = ..
@set 3 = ...
@set 4 = ....
...
...
@set numdots = {dlgstring|Insert text after this character. Enter a number:}
@set dots = {${$numdots}}
Rename REGEXP PATTERN "({$dots})(.*)" TO "\1{dlgstring|Enter text to insert:}\2"
@nodeselect

Unfortunately, iterative interpretation of variable names does not (currently) work so @set dots = {${$numdots}} simply sets {$dots} to null.

Regards, AB

@Admin:

Please edit my last Post.
The second and third Code will not work this way.
Any occurence of "JOERG765" in the code-boxes (Line 9 in second and Line 5 in third box) must be replaced by "TEMPNAME"

Ok Kundal, I've made the changes - is that correct now ?