Looping through string values from a windows command line bat file

Viewed 110543

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.

5 Answers

Something like this, I believe:

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

It won't let me comment, but I wanted to add my 2 cents worth here. The ' do ' has to be on the same line as the right parenthesis of the 'for' command. In other words, this will work:

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

...but this will not:

for %x in (1.1 1.2 2.4 3.9)
    do echo V%x.txt
Related