Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
jhonf
- Posts: 2
- Joined: 31 Oct 2011 10:16
#1
Post
by jhonf » 31 Oct 2011 10:45
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.
-
aGerman
- Expert
- Posts: 4705
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 31 Oct 2011 11:07
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... 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
-
!k
- Expert
- Posts: 378
- Joined: 17 Oct 2009 08:30
- Location: Russia
#3
Post
by !k » 31 Oct 2011 12:43
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"
-
jhonf
- Posts: 2
- Joined: 31 Oct 2011 10:16
#4
Post
by jhonf » 31 Oct 2011 13:04
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.