用于创建具有特定名称的 .txt 文件的批处理文件:String001.txt、String002.txt 等

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

我使用了下面的 for 循环,但只能让它输出一个递增的数字作为名称。它忽略字符串。 (1.txt、2.txt 等)。

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

如何在 .txt 文件名中的每个递增数字前添加静态字符串?

我认为它可能需要另一个变量来将整个字符串和数字存储在一起,然后将其重定向到文件名。但是我难住了...

感谢您的帮助。

除了数字后跟 .txt 扩展名之外,您的代码不会写入任何内容。

试试这个:

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

要有前导零,您需要不同的方法:

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