Adding number based on a condition
Hello,
I want to add 0 at the position 1 backwards to every file name that ends with a number.
Otherwise add 00 to the name.
For instance:
file 1.txt -> file 01.txt
file.txt -> file 00.txt
file 2.txt -> file 02.txt
Can this be done without JavaScript?
I want to add 0 at the position 1 backwards to every file name that ends with a number.
Otherwise add 00 to the name.
For instance:
file 1.txt -> file 01.txt
file.txt -> file 00.txt
file 2.txt -> file 02.txt
Can this be done without JavaScript?
Reply to #1:
Hi Adrian,
Sure, you can do it in two steps:
1) RENUMBER method:
Number position: 1
Change to: Relative to existing number
Number difference: 0
Zero padding: Manual
Number length: 2
Apply to: Name
2) REPLACE method:
Replace: ^([a-z]+)$
Replace with: $1 00
Occurrence: All or 1st
Case sens.: NO
Use regular expressions: YES
Apply to: Name
The first just pads numbers already there. The second adds <space>00 only if there is no number at the end of the filename.
Best,
DF
Hi Adrian,
Sure, you can do it in two steps:
1) RENUMBER method:
Number position: 1
Change to: Relative to existing number
Number difference: 0
Zero padding: Manual
Number length: 2
Apply to: Name
2) REPLACE method:
Replace: ^([a-z]+)$
Replace with: $1 00
Occurrence: All or 1st
Case sens.: NO
Use regular expressions: YES
Apply to: Name
The first just pads numbers already there. The second adds <space>00 only if there is no number at the end of the filename.
Best,
DF
Reply to #2:
Thanks it worked, but I had to modify #2 to: ^(?!.*\d$)(.+)$
Thanks it worked, but I had to modify #2 to: ^(?!.*\d$)(.+)$
Reply to #3:
Hi Adrian,
So if I understand, you must have some number(s) in your filename(s). Which you didn't specify. I can only work with what I'm given in the examples, my friend. Obviously what I wrote worked with what you specified. Glad you worked it out though! :)
Probably ([^\d ]+)$ would work too.
EDIT: > Probably ([^\d ]+)$ would work too.
Yeah, probably not. When I added another number to the filename I ended up having to use two renumber methods to get the result. So never mind! :) Much easier using a script, though.
END EDIT
Best,
DF
Hi Adrian,
So if I understand, you must have some number(s) in your filename(s). Which you didn't specify. I can only work with what I'm given in the examples, my friend. Obviously what I wrote worked with what you specified. Glad you worked it out though! :)
Probably ([^\d ]+)$ would work too.
EDIT: > Probably ([^\d ]+)$ would work too.
Yeah, probably not. When I added another number to the filename I ended up having to use two renumber methods to get the result. So never mind! :) Much easier using a script, though.
END EDIT
Best,
DF