I'm having issues getting this to pad leading zeros
so i have a list of *.pdf named 1.pdf - 999.pdf in a folder. inside JobIDs.txt is the file name needed for each pdf in order line 1 for 1.pdf , 2 for 2.pdf so on so on
i get a new set of pdf files everyday 7 days a week issue I'm having is when i dir the directory it will list
1
10
11
13
then 100s
2
20s
200s
so i need to rename my file from NUMBER.pdf to "PADDEDNUMBER - %%a.pdf"
example line from JobIDs.txt
ERIE - 31102 - 191786 - 8305 MAPLE TRACT RD
so input would be 1.pdf to 001 - ERIE - 31102 - 191786 - 8305 MAPLE TRACT RD.pdf
setlocal EnableDelayedExpansion
set count=0
set /a "num=001"
@echo off
for /f "tokens=* delims= " %%a in (JobIDs.txt) do (
echo Renaming !count!.pdf to !count! - %%a.pdf
set /a count+=1
echo num: %num%
set "num=1%num%"
set /a num=num+1
set /a num=%num:~1%
echo num: %num%
REM "This works outside of for /f but not inside"
REM This works with out padding
REM ren !count!.pdf "!count! - %%a.pdf"
echo ren !count!.pdf "%num% - %%a.pdf"
Rem Does not work
pause
)
echo Done
having trouble with padding zeros in a for /f
Moderator: DosItHelp
Re: having trouble with padding zeros in a for /f
Your approach mainly doesn't work, becuase you are using the normal expansion instead of the delayed one.
Padding to three digits in your example could be done this way:
penpen
Padding to three digits in your example could be done this way:
Code: Select all
set "paddedCount=000!count!"
set "paddedCount=!paddedCount:~-3!"
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: having trouble with padding zeros in a for /f
this should look like this in the command line.
Code: Select all
< JobIDs.txt cmd /v /c "set "x=" & (for /l %i in (1001 1 1999) do @ set /p "x=" && >nul set /a "padNr=%i,nr=padNr%1000" && echo ren "!Nr!.pdf" "!padNr:~1! - !x!") "
Re: having trouble with padding zeros in a for /f
Thank you ill give these a try when i get back home