views:

31

answers:

2

I am trying to create a batch script for my Windows machine that loops through a list of (string/decimal) values and uses each value as a parameter inside the loop.

Below is an example of a simple for loop I would like to use to display all the different version files (from my list)

FOR ? in ('1.1','1.2','2.4','3.9') do echo V[value_from_for_loop].txt

I am having trouble in how to loop through each item and use a variable in my echo statement.

+1  A: 
for %x in (1.1 1.2 2.4 3.9) do echo V%x.txt

For use in a batch file you'll have to double the %:

for %%x in (1.1 1.2 2.4 3.9) do echo V%%x.txt
Joey
A: 

...and if you want to read the variables from a text file, line by line:

for /f "tokens=*" %a in (c:\path\to\my-values.list) do echo.  Version%~nxa.txt

This assumes the content of my-values.list to be an arbitrary long list of things, something like:

1.1
1.2
2.4
3.9
3.9.1
3.9.2
3.91
3.91.1
...
pipitas
-1 sorry but this has nothing to do with the question asked
David Liddle
@David Liddle: Of course it has -- you just don't understand (yet) how :-) -- Assume a very long text file `values.list`, where you have all the values listed, 1 per line. Would be very un-handy to type all these on the commandline again (which itself has length limits). I had to do exactly that thing with ~2.500 values a couple of weeks ago. And the list I had created thru another batch. I just didn't need to simply+boringly `do echo ...` but more interesting stuff instead... ;-)
pipitas