Share this page 

Increment a counter in a batch fileTag(s): Misc Prog HowTo


We want to generate an output where a counter is incremented.
wrapper.java.classpath.1=../lib/activation.jar
wrapper.java.classpath.2=../lib/commons-digester-rss.jar
wrapper.java.classpath.3=../lib/DirWatch.jar
wrapper.java.classpath.4=../lib/JavaCom.jar
wrapper.java.classpath.5=../lib/mail.jar
wrapper.java.classpath.6=../lib/mydb.jar
wrapper.java.classpath.7=../lib/MyJar.jar
The code :

@echo off
setlocal enabledelayedexpansion
set /A Counter=1
for %%f in (*.jar) do (
  echo wrapper.java.classpath.!Counter!=../lib/%%f
  set /A Counter+=1
)