Hi All,
Are there any books or websites that teach people how to write batch files?
I was playing with batch code I found on www.computing.net and the stupidest thing happen. I renamed Old1.jpg to File01.jpg, and can do that till I hit 09.
When I try that, instead of File09.jpg, it goes balistic and name it as File008.jpg. The more file I have the more leading 0's it adds.
Here is my code:
@echo off
set Count=00
dir /b | findstr "[0-9].jpg" > tmp1.txt
sort tmp1.txt > tmp2.txt
for /f %%a in (tmp2.txt) do (call :incr
call :ReNumber %%a %%Count%%)
erase tmp?.txt *.tmp
exit /b
:incr
set /a Count=%Count%+1
if %count% LSS 10 set Count=00%count%
goto :eof
:ReNumber %1 %2
if exist %1 ( rem echo renamed %1 File%2.jpg
ren %1 %1.tmp
ren %1.tmp File%2.jpg) else (rem echo ren renamed %1
File%2.jpg
ren %1 File%2.jpg)
goto :eof
And here is the Error:
renamed Old1.jpg File01.jpg
renamed Old2.jpg File02.jpg
renamed Old3.jpg File03.jpg
renamed Old4.jpg File04.jpg
renamed Old5.jpg File05.jpg
renamed Old6.jpg File06.jpg
renamed Old7.jpg File07.jpg
renamed Old8.jpg File08.jpg
Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).
renamed Old9.jpg File008.jpg
Thank you in advance for any help