#1 2021-01-01 23:16

Rincewindwiz
Member
Registered: 2021-01-01
Posts: 3

Pad out numbers

Hi
I have a bunch of files that are named with a string of "text" + "-"+a number+".extension"
The number does not have leading zeroes so the files appear in the wrong order
text-1.ext
text-10.ext
text-100.ext
text-101.ext

And I want
text-001.ext
text-002.ext
text-003.ext
etc

So I want to replace
"text-?.ext" with "text-00?.ext" and
"text-??.ext" with "text-0??.ext"

But it seems ? is not allowed in the replace part of a rule

So how can I pad out the numbers with leading zeros?

TFAI

On a more general note, it would. IMHO, be very useful to be able to use ? and * in the replace part where they refer to the character(s) that they replaced in the find part of the command.

Offline

#2 2021-01-05 14:01

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,067

Re: Pad out numbers

You can use the Padding rule to apply the zero padding to existing numbers.

See https://www.den4b.com/wiki/ReNamer:Rules:Padding

Regarding the second question. You can enable an option to interpret wildcards and back-references in the Replace rule.

See https://www.den4b.com/wiki/ReNamer:Rules:Replace

Offline

#3 2021-01-05 22:53

Rincewindwiz
Member
Registered: 2021-01-01
Posts: 3

Re: Pad out numbers

Padding: That's very clever. I thought it only applied to numbers being added. Silly thought really as that is in serialise

Not sure I get backreferences
I'll have a play and see if I can work it out
Thx

Offline

#4 2021-01-06 00:14

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,067

Re: Pad out numbers

Rincewindwiz wrote:

So I want to replace
"text-?.ext" with "text-00?.ext" and
"text-??.ext" with "text-0??.ext"

That would be:

"text-?.ext" with "text-00$1.ext" and
"text-??.ext" with "text-0$1$2.ext"

With wildcards and back-references in the Replace rule.

Offline

#5 2021-01-06 17:14

Rincewindwiz
Member
Registered: 2021-01-01
Posts: 3

Re: Pad out numbers

Thank you.

And if I have understood it correctly,
TextABCD-1.ext -> TextABCD-001.ext
TextADCB-1.ppt-> TextCDAB-001.ppt
TextZZ-2.xls   -> TextZZ-002.xls
TextXXX-13 .txt  ->  TextXXX-0013.txt

can all be done with
Find        Text*-?.*
Replace  Text$1-00$2.$3
with wildcards and backrefs ticked

Offline

#6 2021-01-06 20:24

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,067

Re: Pad out numbers

Rincewindwiz wrote:

And if I have understood it correctly,
TextABCD-1.ext -> TextABCD-001.ext
TextADCB-1.ppt-> TextCDAB-001.ppt
TextZZ-2.xls   -> TextZZ-002.xls
TextXXX-13.txt  ->  TextXXX-0013.txt

can all be done with
Find        Text*-?.*
Replace  Text$1-00$2.$3
with wildcards and backrefs ticked

The first 3 examples should work, but the 4th example will not.

"TextXXX-13.txt" will not match the "Text*-?.*" pattern, because "?" matches exactly 1 character.

This is where you should start using Regular Expressions instead of Wildcards.

Offline

Board footer

Powered by FluxBB