Page 1 of 1

Increase counter written inside bat file every time it runs

Posted: 31 Oct 2011 10:45
by jhonf
Hi, I have a bat file which after launch converts one picture from sequence (using nconvert) and then closes. At the beginning of bat file there is picture number sets to variable and then it uses in other places of this bat file.

Code: Select all

SET PictureNumber=123
nconvert -overwrite -out png "part04 %PictureNumber%.bmp"


How can I increase this number and write it down it bat file everytime it launches? Is there a possibility to replace exactly sting in file, or may be by using some other file where this number stores.

Re: Increase counter written inside bat file every time it r

Posted: 31 Oct 2011 11:07
by aGerman
You could save the next number in a text file.
Before you run the batch the first time you have to create the txt manually:
nextnumber.txt

Code: Select all

124

... otherwise it will start with 1.

The batch code:

Code: Select all

set /a PictureNumber=1
set /p "PictureNumber="<"nextnumber.txt"
nconvert -overwrite -out png "part04 %PictureNumber%.bmp"
set /a PictureNumber+=1
>"nextnumber.txt" echo %PictureNumber%


Regards
aGerman

Re: Increase counter written inside bat file every time it r

Posted: 31 Oct 2011 12:43
by !k
output is "part04 %PictureNumber%.png" ?

Code: Select all

set "PictureNumber=001"
for /f "tokens=2 delims=. " %%a in ('dir /b/o-n "part04 *.png"') do (set /a PictureNumber=1%%a+1 &goto:next)
:next
nconvert -overwrite -out png "part04 %PictureNumber:~-3%.bmp"

Re: Increase counter written inside bat file every time it r

Posted: 31 Oct 2011 13:04
by jhonf
Thanks a lot for such quick answers, I'm already using first one, but going to try second one as well, because it is a little bit more elegant and doesn't require another file. But they both are useful in different situations.