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.
For use in a batch file you'll have to double the
%
:Assume you have a very long list of values which will be very uncomfortable to type on the commandline. Also, there is a length limit for the DOS command line.
In this case the values may be stored in an arbitrarily long file, one per line. Call it
my-values.list
, with a content similar to:Now you could read the variables from this text file, line by line:
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:
...but this will not:
@Јοеу's answer works great,
here is how I've used it, to 'walk' a pre-set list of files in a specific order.
the reason it looks like a vertical list is so it will be easier to add or remove more items. (and 'echo' with 'dot' is for one empty line).
the output will look like this:
** p.s. for file name listing one should prefer using something like this:
for %%e in (*.dll) do (....