I have 20 files, 1.txt, 2.txt, ... 19.txt, 20.txt.
I want to rename 1-9 as 01-09.
Why does this regex rename change not only the single digit text files, but the double digits also?
The rename command is shown and defined as follows...
And the result is...
I want to rename 1-9 as 01-09.
Why does this regex rename change not only the single digit text files, but the double digits also?
The rename command is shown and defined as follows...
Code:
*ren /n ::^(\d)\.txt$ ::0\1.txt
-------------------------------
*ren - rename command overriding aliases
/n - just show me what would happen
:: - it's the source filename regex
^ - beginning of line
( - start capture group
\d - a single digit
) - end capture group
\. - escaped period overriding the wildcard any character effect
txt - the text string "txt"
$ - end of line
:: - it's the target file regex
0 - the text string "0"
\1 - use the first matching group from the source filename regex
.txt - the text string ".txt"
Code:
[C:\temp]
12:20:45 $ *ren /n ::^(\d)\.txt$ ::0\1.txt
C:\temp\1.txt -> C:\temp\01.txt
C:\temp\10.txt -> C:\temp\100.txt
C:\temp\11.txt -> C:\temp\101.txt
C:\temp\12.txt -> C:\temp\102.txt
C:\temp\13.txt -> C:\temp\103.txt
C:\temp\14.txt -> C:\temp\104.txt
C:\temp\15.txt -> C:\temp\105.txt
C:\temp\16.txt -> C:\temp\106.txt
C:\temp\17.txt -> C:\temp\107.txt
C:\temp\18.txt -> C:\temp\108.txt
C:\temp\19.txt -> C:\temp\109.txt
C:\temp\2.txt -> C:\temp\02.txt
C:\temp\20.txt -> C:\temp\200.txt
C:\temp\3.txt -> C:\temp\03.txt
C:\temp\4.txt -> C:\temp\04.txt
C:\temp\5.txt -> C:\temp\05.txt
C:\temp\6.txt -> C:\temp\06.txt
C:\temp\7.txt -> C:\temp\07.txt
C:\temp\8.txt -> C:\temp\08.txt
C:\temp\9.txt -> C:\temp\09.txt
20 files would be renamed