0

Ive used the for loop below, but can only get it to ouput an incrementing number as the name. It ignores the string. (1.txt, 2.txt, etc.).

For /l %%x (1, 1, 9) do (echo string%%x > %%x.txt)

How do I add the static string in front of each incrementing number in the .txt file name?

I think it may need another variable to store the whole string and number together, then redirect that to filenames. But Im stumped...

Thanks for help.

Nick.Mc
  • 18,304
  • 6
  • 61
  • 91
Glycoversi
  • 77
  • 8

2 Answers2

1

Your code makes no effort to write anything but the number followed by the .txt extension.

Try this instead:

for /l %%x (1, 1, 9) do (echo string%%x > String%%x.txt)
Ken White
  • 123,280
  • 14
  • 225
  • 444
1

To have leading zeroes you need a different approach:

@Echo off
for /l %%n in (1001,1,1009) do set n=%%n&call Echo string%%n:~-3%% >string%%n:~-3%%.txt