Hello,
I am looking at the Format() function but I don't understand at all how it is used (nor if it is useful for my script).
What I want is to create a file renaming function with index at the end like 000 001 002 etc.
It is easy to get the digit part of the file but I don't see how can I add 1 to the last currently used index.
If I have test.txt.053 then the next file should be test.txt.054
But if I do 053 + 1 it will give 54.
Is there a way to use format to add missing 0 in front of the index ?
Or it is not at all used for that.
Thanks !
PS : an easy way is just to count the length and loop on adding "0" but it is ugly or use the RegExMatch to get 0 if any and other digits.
Format() function Topic is solved
-
- Posts: 44
- Joined: 02 Sep 2014, 04:14
Re: Format() function Topic is solved
Hallo,
try:or:
try:
Code: Select all
Name = test.txt.053
RegExMatch(Name, "\d+$", Number)
MsgBox,% Number
NextName := Format("test.txt.{:03}", Number+1) ; {:03} = total Number width is 3
MsgBox,% NextName
Code: Select all
Name = test.txt.053
RegExMatch(Name, "^(.*?)(\d+)$", Part)
MsgBox,% Part1 " > " Part2
NextName := Format(Part1 "{:0" StrLen(Part2) "}", Part2+1)
MsgBox,% NextName
-
- Posts: 44
- Joined: 02 Sep 2014, 04:14
Re: Format() function
Nice !Rohwedder wrote: ↑24 May 2024, 04:29Hallo,
try:or:Code: Select all
Name = test.txt.053 RegExMatch(Name, "\d+$", Number) MsgBox,% Number NextName := Format("test.txt.{:03}", Number+1) ; {:03} = total Number width is 3 MsgBox,% NextName
Code: Select all
Name = test.txt.053 RegExMatch(Name, "^(.*?)(\d+)$", Part) MsgBox,% Part1 " > " Part2 NextName := Format(Part1 "{:0" StrLen(Part2) "}", Part2+1) MsgBox,% NextName
Now I see how it works !
Thanks again !