Multi-Rename Tool modify counter at different positions
Moderators: white, Hacker, petermad, Stefan2
Multi-Rename Tool modify counter at different positions
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?
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?
Re: Multi-Rename Tool modify counter at different positions
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?
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?
Re: Multi-Rename Tool modify counter at different positions
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.
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.
Re: Multi-Rename Tool modify counter at different positions
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.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?
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?
Re: Multi-Rename Tool modify counter at different positions
Yes, the order in the example is not correct and I forgot to mention that 'text' can represent different strings.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.
Anyway, thank you for your solution, it works too!
Re: Multi-Rename Tool modify counter at different positions
Hi 8emi95, thank you for your feedback.
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.
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.
Re: Multi-Rename Tool modify counter at different positions
Oh, I see. Thanks!Stefan2 wrote: ↑2019-09-05, 14:57 UTC Hi 8emi95, thank you for your feedback.
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.
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.
Re: Multi-Rename Tool modify counter at different positions
Ah, got it. Just needed a ? quantifier in the first (.+) group for laziness.8emi95 wrote: ↑2019-09-05, 21:08 UTCOh, I see. Thanks!Stefan2 wrote: ↑2019-09-05, 14:57 UTC Hi 8emi95, thank you for your feedback.
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.
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.
Re: Multi-Rename Tool modify counter at different positions
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.
Re: Multi-Rename Tool modify counter at different positions
Thankfully, the files I was renaming with didn't start with digits so it worked. Thanks for everything again!Stefan2 wrote: ↑2019-09-06, 09:16 UTCNo, 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.