Multi-Rename Tool modify counter at different positions

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
8emi95
Junior Member
Junior Member
Posts: 6
Joined: 2019-09-04, 17:00 UTC

Multi-Rename Tool modify counter at different positions

Post by *8emi95 »

Hello!

I'm trying to modify (not necessarily reset) the counter in filenames where the counter itself is at different positions.

From this:

texttext001_sth002_note
texttext002_sth003_note
text004_sth005
texttexttext005_sth006
text006_sth009
texttexttext009_sth010_note
texttexttext010_sth011

To this:

texttext001_sth001_note
texttext002_sth002_note
text004_sth003
texttexttext005_sth004
text006_sth005
texttexttext009_sth006_note
texttexttext010_sth007

I would need to replace sth[0-9]{3} with sth[C:3] but is not possible to use [C] in the replace field to my best knowledge.

I'd like to edit the 3 formats at once. Using [N13-16][C:3][19-], etc for each format is not effective because the 3 formats are mixed in the file list so much that doing it by hand instead would be faster.
And I only want to replace the 3 digits after the 'sth' substring, not the ones after the 'text' substring.

Does anybody know a way to make it work somehow?
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Multi-Rename Tool modify counter at different positions

Post by *Stefan2 »

You know the real order of your files is like:
text004_sth005
text006_sth009
texttext001_sth002_note
texttext002_sth003_note
texttexttext005_sth006
texttexttext009_sth010_note
texttexttext010_sth011

NOT 1,2,4,5,6... but 4,6,1,2...

So even if you could use [C], the counter would be in a different order as your posted examples suggest. So, what do you really want/need?






FROM:
text004_sth005
text006_sth009
texttext001_sth002_note
texttext002_sth003_note
texttexttext005_sth006
texttexttext009_sth010_note
texttexttext010_sth011

TO:
text004_sth001
text006_sth002
texttext001_sth003_note
texttext002_sth004_note
texttexttext005_sth005
texttexttext009_sth006_note
texttexttext010_sth007



USE:

Filename mask: [C:3]#[N]
Extension: [E]
Search for: (\d+)#(.+)(sth)\d+(.+)?
Replace with: $2$3$1$4
☐ ⩟ ☐ 1x ☐ [E] ☑ RegEx ☐ Subst

Rename.
Done?



or like that, depending on your real name pattern

you could also use
Search for: (\d\d\d)#(.+)(sth)\d\d\d(.+)?
to be more specific


HTH? :roll:
User avatar
nsp
Power Member
Power Member
Posts: 1803
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Multi-Rename Tool modify counter at different positions

Post by *nsp »

Hi,

You have several schemes to apply and you also have to fix ordering.
Ordering should be done before calling Rename.
You should add the counter string at the end of the file name in the rename file Mask and then regex to put it at the right place
Mask: [N][C:3]
search for ^(.+_sth)[0-9]{3}(.*)([0-9]{3})$
replace: $1$3$2

This should do the job in your case. But you must select only relevant file for renaming as the counter will be incremented even if the search string is not found.
8emi95
Junior Member
Junior Member
Posts: 6
Joined: 2019-09-04, 17:00 UTC

Re: Multi-Rename Tool modify counter at different positions

Post by *8emi95 »

Stefan2 wrote: 2019-09-05, 08:15 UTC You know the real order of your files is like:
text004_sth005
text006_sth009
texttext001_sth002_note
texttext002_sth003_note
texttexttext005_sth006
texttexttext009_sth010_note
texttexttext010_sth011

NOT 1,2,4,5,6... but 4,6,1,2...

So even if you could use [C], the counter would be in a different order as your posted examples suggest. So, what do you really want/need?






FROM:
text004_sth005
text006_sth009
texttext001_sth002_note
texttext002_sth003_note
texttexttext005_sth006
texttexttext009_sth010_note
texttexttext010_sth011

TO:
text004_sth001
text006_sth002
texttext001_sth003_note
texttext002_sth004_note
texttexttext005_sth005
texttexttext009_sth006_note
texttexttext010_sth007



USE:

Filename mask: [C:3]#[N]
Extension: [E]
Search for: (\d+)#(.+)(sth)\d+(.+)?
Replace with: $2$3$1$4
☐ ⩟ ☐ 1x ☐ [E] ☑ RegEx ☐ Subst

Rename.
Done?



or like that, depending on your real name pattern

you could also use
Search for: (\d\d\d)#(.+)(sth)\d\d\d(.+)?
to be more specific


HTH? :roll:
Yeah, I neglected to state that the 'text' part could mean any kind of string. Sorry about that. It was just to show that the counters are at different positions but I didn't pay attention to the order in the example.

Regardless, this solution works. Thank you!

Can you help me understand it a bit? I know some regexp but I don't understand the purpose of the # in the filename mask ad the search for fields. I see the [C:3] counter and the (\d\d\d) digits are both before the #. Does this # indicate that the counter could be anywhere in the name or something?
8emi95
Junior Member
Junior Member
Posts: 6
Joined: 2019-09-04, 17:00 UTC

Re: Multi-Rename Tool modify counter at different positions

Post by *8emi95 »

nsp wrote: 2019-09-05, 08:36 UTC Hi,

You have several schemes to apply and you also have to fix ordering.
Ordering should be done before calling Rename.
You should add the counter string at the end of the file name in the rename file Mask and then regex to put it at the right place
Mask: [N][C:3]
search for ^(.+_sth)[0-9]{3}(.*)([0-9]{3})$
replace: $1$3$2

This should do the job in your case. But you must select only relevant file for renaming as the counter will be incremented even if the search string is not found.
Yes, the order in the example is not correct and I forgot to mention that 'text' can represent different strings.
Anyway, thank you for your solution, it works too!
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Multi-Rename Tool modify counter at different positions

Post by *Stefan2 »

Hi 8emi95, thank you for your feedback.

8emi95 wrote: 2019-09-05, 14:11 UTC Can you help me understand it a bit?
I know some regexp but I don't understand the purpose of the # in the filename mask ad the search for fields.


The # is just a random char to get the right part in the search&replace. An anchor.
Filename mask: [C:3]#[N]
Search for: (\d+)#(.+)(sth)\d+(.+)?

In your case it's not really necessary, but if your filenames would start with an digit also,
and if the digits would have different lengths, that would be helpful (e.g. for others finding this example in future).


FROM:
4text_sth005
06text_sth009
TO:
4text_sth001
06text_sth002


A 'just in case' kind off a safety net.



 
8emi95
Junior Member
Junior Member
Posts: 6
Joined: 2019-09-04, 17:00 UTC

Re: Multi-Rename Tool modify counter at different positions

Post by *8emi95 »

Stefan2 wrote: 2019-09-05, 14:57 UTC Hi 8emi95, thank you for your feedback.

8emi95 wrote: 2019-09-05, 14:11 UTC Can you help me understand it a bit?
I know some regexp but I don't understand the purpose of the # in the filename mask ad the search for fields.


The # is just a random char to get the right part in the search&replace. An anchor.
Filename mask: [C:3]#[N]
Search for: (\d+)#(.+)(sth)\d+(.+)?

In your case it's not really necessary, but if your filenames would start with an digit also,
and if the digits would have different lengths, that would be helpful (e.g. for others finding this example in future).


FROM:
4text_sth005
06text_sth009
TO:
4text_sth001
06text_sth002


A 'just in case' kind off a safety net.
Oh, I see. Thanks!

Do you know how could I alter this if there are 2 instances of the _sth[C:3]_ substring and I only want to change the first one? It finds the second one now. I was trying to figure it out but my regexp knowledge is not enough for this I think.
8emi95
Junior Member
Junior Member
Posts: 6
Joined: 2019-09-04, 17:00 UTC

Re: Multi-Rename Tool modify counter at different positions

Post by *8emi95 »

8emi95 wrote: 2019-09-05, 21:08 UTC
Stefan2 wrote: 2019-09-05, 14:57 UTC Hi 8emi95, thank you for your feedback.

8emi95 wrote: 2019-09-05, 14:11 UTC Can you help me understand it a bit?
I know some regexp but I don't understand the purpose of the # in the filename mask ad the search for fields.


The # is just a random char to get the right part in the search&replace. An anchor.
Filename mask: [C:3]#[N]
Search for: (\d+)#(.+)(sth)\d+(.+)?

In your case it's not really necessary, but if your filenames would start with an digit also,
and if the digits would have different lengths, that would be helpful (e.g. for others finding this example in future).


FROM:
4text_sth005
06text_sth009
TO:
4text_sth001
06text_sth002


A 'just in case' kind off a safety net.
Oh, I see. Thanks!

Do you know how could I alter this if there are 2 instances of the _sth[C:3]_ substring and I only want to change the first one? It finds the second one now. I was trying to figure it out but my regexp knowledge is not enough for this I think.
Ah, got it. Just needed a ? quantifier in the first (.+) group for laziness.
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Multi-Rename Tool modify counter at different positions

Post by *Stefan2 »

8emi95 wrote: 2019-09-05, 21:28 UTC...

Ah, got it. Just needed a ? quantifier in the first (.+) group for laziness.
No, a non-greedy-'?' wouldn't help here in my way of doing that, if the original name would start with digits too
and I add additional digits (the counter) to the beginning.


4text_sth005
0014text_sth005



Only an explicit specification of the length of the counter digits "\d{3}" would help, or a complete different way to go.





 
8emi95
Junior Member
Junior Member
Posts: 6
Joined: 2019-09-04, 17:00 UTC

Re: Multi-Rename Tool modify counter at different positions

Post by *8emi95 »

Stefan2 wrote: 2019-09-06, 09:16 UTC
8emi95 wrote: 2019-09-05, 21:28 UTC...

Ah, got it. Just needed a ? quantifier in the first (.+) group for laziness.
No, a non-greedy-'?' wouldn't help here in my way of doing that, if the original name would start with digits too
and I add additional digits (the counter) to the beginning.


4text_sth005
0014text_sth005



Only an explicit specification of the length of the counter digits "\d{3}" would help, or a complete different way to go.





 
Thankfully, the files I was renaming with didn't start with digits so it worked. Thanks for everything again!
Post Reply