# Solved: Problem with a counter in a batch file



## ml41782 (Dec 14, 2008)

Good morning, 

I have a batch file the builds out a series of other batch files. I need to increment a number within each of the batch files as they are built. The problem is that I can't seem to get the batch file to increment the number. This has to be something simple that I'm over looking. 
The number starts at 20213 and ends with 20225

rem stage 02 
rem 
set /a counter=20213 
rem 
SETLOCAL ENABLEEXTENSIONS 
SETLOCAL ENABLEDELAYEDEXPANSION 
for /F "tokens=1" %%c in (File.card2) do ( 
@echo.|set /p="cscript.exe wmcmd.vbs -vdevice ">%%c.bat 
findstr /i "Video" %%c > %%c.av 
for /F "tokens=1-4" %%f in (%%c.av) do @echo.|set /p="%%f " >>%%c.bat 
@echo.|set /p=" -adevice " >>%%c.bat 
findstr /i "Audio" %%c > %%c.aa 
for /F "tokens=1-4" %%d in (%%c.aa) do @echo.|set /p="%%d " >> %%c.bat 
@echo.|set /p=" -maxpacket 1400 -author %%c -description %%c -broadcast %counter% ">> %%c.bat 
@echo.|set /p=" -loadprofile f4.prx -duration 86400 ">>%%c.bat 
set /a counter=%counter%+1) 
del /q *.aa 
del /q *.av 
del /q *.card 
endlocal
rem file completed


FILE.CARD2
==============
1A.card 
1B.card 
1C.card 
1D.card 
3A.card 
3B.card 
3C.card 
3D.card 
4A.card 
4B.card 
4C.card 
4D.card
==============


----------



## ml41782 (Dec 14, 2008)

I was on the right track and I found the error of my ways.

rem stage 02 
rem 
set /a counter=20213 
echo %counter% begin >>Mikey.txt 
rem 
SETLOCAL ENABLEEXTENSIONS 
SETLOCAL ENABLEDELAYEDEXPANSION 
for /F "tokens=1" %%c in (File.card2) do ( 
set /a counter+=1 
@echo.|set /p="cscript.exe wmcmd.vbs -vdevice ">%%c.bat 
findstr /i "Video" %%c > %%c.av 
for /F "tokens=1-4" %%f in (%%c.av) do @echo.|set /p="%%f " >>%%c.bat 
@echo.|set /p=" -adevice " >>%%c.bat 
findstr /i "Audio" %%c > %%c.aa 
for /F "tokens=1-4" %%d in (%%c.aa) do @echo.|set /p="%%d " >> %%c.bat 
@echo.|set /p=" -maxpacket 1400 -author %%c -description %%c -broadcast !counter! ">> %%c.bat 
@echo.|set /p=" -loadprofile f4.prx -duration 86400 ">>%%c.bat) 
del /q *.aa 
del /q *.av 
del /q *.card 
endlocal

 Add to the list of quoted messages   Quick edit   Edit this message


----------



## Ent (Apr 11, 2009)

Thank you for coming back to share your solution. 

Could you please click "Mark Solved" at the top of this thread? This tells future searchers that there is an answer here, and also helps to prevent volunteers wasting their time on questions that have already been answered.


----------

