简体   繁体   English

如何批量创建多行文本文件?

[英]How do I create a multiline text file with batch?

I'd like from a batch script to create a text file inside each folder in a given directory with 2 lines : the first line containing the name of the folder in which the text file is located, between brackets [ ], the second line with a text of my choice.我想通过批处理脚本在给定目录中的每个文件夹中创建一个文本文件,其中包含 2 行:第一行包含文本文件所在文件夹的名称,在方括号 [ ] 之间,第二行与我选择的文本。

For example :例如 :

[test]
abcd123

I started writing the code :我开始编写代码:

cd C:\test
for /d %%a in (*) do (echo %%a > %%a\test.txt)

But I have no idea how to add the brackets and a 2nd line.但我不知道如何添加括号和第二行。

Can you help please ?你能帮忙吗?

Thanks.谢谢。

One of the purposes of the parentheses is to create a command block that the FOR command can use to execute multiple lines of code.括号的目的之一是创建一个命令块, FOR命令可以使用它来执行多行代码。

So use that to your advantage.因此,请充分利用它。

cd C:\test
for /d %%a in (*) do (
    echo [test]>"%%a\test.txt"
    echo %%a >>"%%a\test.txt"
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM