Search code examples
batch-filetext-filescreatefilebatching

Batch file to create .txt files with specific names: String001.txt, String002.txt, etc


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.


Solution

  • 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