Search code examples
batch-filedos

How to use an iterating variable in a for loop in MS-DOS batch files?


I have a batch file which does something like this

for %%a in (1 2 3 4 5) do dir > %%a.output

%%a just gives me a .

How can I use the value of the variable %%a to assign the file name (e.g. 1.output, 2.output) ?


Solution

  • You have to surround your variable:

    for %a in (1 2 3 4 5) do dir > %a%.output