Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looping through string values from a windows command line bat file

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.

like image 956
David Avatar asked Aug 09 '10 12:08

David


People also ask

How do I loop a text file in a batch file?

set input="path/to/file. txt" for /f "tokens=* delims=[" %i in ('type "%input%" ^| find /v /n ""') do ( set a=%i set a=!a:*]=]! echo:!a:~1!) Works with leading whitespace, blank lines, whitespace lines.

What does @echo off do in bat?

Example# @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.

How do you run a loop in CMD?

FOR /D - Loop through several folders. FOR /L - Loop through a range of numbers. FOR /F - Loop through items in a text file. FOR /F - Loop through the output of a command.


1 Answers

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 
like image 185
Joey Avatar answered Sep 19 '22 15:09

Joey