[英]Copy text files into one file including filenames
From the Windows command prompt it's possible to collect all text files into one file using 在Windows命令提示符下,可以使用以下命令将所有文本文件收集到一个文件中
copy *.txt all_text_files.txt
Is it possible to add the name of each file added in front of the file in question? 是否可以在问题文件之前添加每个文件的名称? In my example I have two text files a & b. 在我的示例中,我有两个文本文件a和b。
a.txt consists of one line: a.txt包含一行:
Cheese
b.txt also consists of one line: b.txt也包含一行:
Monkeys
The new file would be: 新文件将是:
a.txt
Cheese
b.txt
Monkeys
If you write it directly in the command line, this should work. 如果您直接在命令行中编写它,那应该可以。 If you want to make a script I believe you need to put double %
如果您想编写脚本,我相信您需要加倍%
for %f in (*.txt) do (
echo "%f"
type "%f"
) > all_text_files.txt
type *.txt >allfiles.out 2>&1
ren allfiles.out allfiles.txt
type
types all matching files. type
所有匹配文件的类型。 The file contents goes to STDOUT, the filenames are printed to STDERR. 文件内容转到STDOUT,文件名打印到STDERR。 So just redirect both to the new file. 因此,只需将它们都重定向到新文件即可。 Choose a different extension to avoid recursive handling. 选择其他扩展名以避免递归处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.