Solved Rename a file adding leading zeros

June 8, 2011 at 23:18:46
Specs: WinXP
Hi everyone. I am new to batch programming and need some help renaming a file. The file will be renamed using information found on line one of the file. The filename will be composed of 5 numbers, beginning with leading zeros. So if the number on line one is 12, the filename will be 00012.txt. If the number on line one is 137, then the filename will be 00137.txt. So the problem is basically how to determine the length of the original number (2 in the first example, 3 in the second), so that the leading zeros added will bring the character length to 5.

Any help will be greatly appreciated.

See More: Rename a file adding leading zeros

Report •

June 9, 2011 at 03:09:00
✔ Best Answer
Assumed the first line of the file holds just the number and nothing else starting at position one (or zero), then

set /P num=< file.txt
set num=0000%num%
ren file.txt %num:~-5%.txt

Report •
Related Solutions

Ask Question