如何将所有文本文件合并为带有断线的单个文件? [英] How to Merge all Text files in a Single file with Broken Lines?
问题描述
我正在使用以下代码将文件夹中的所有文本文件合并为一个简单的文件,问题是该代码不会断行并且最终会混合单词.
I'm using the codes below to combine all text files from a folder to a simple files, the problem is that the code does not break lines and ends up blending the words.
copy *.txt Combined.txt
Echo.
Echo Done!
Echo.
pause
结束时,他会像这样:
abcblue
123abcyellow
123abc
我希望它像这样运行:
ABC
blue
123
abc
yellow
123
abc
怎么了?
注意:我在互联网上找到了这段代码,看起来像这样:
NOTE: I found this snippet of code on the internet and it looks like the subject:
FOR %f IN (*.txt) DO type %f >> Combined.txt & echo. >> Combined.txt
在这种情况下:
type file1.txt >> newfile.txt
echo. >> newfile.txt
type file2.txt >> newfile.txt
echo. >> newfile.txt
type file3.txt >> newfile.txt
echo. >> newfile.txt
但是我需要它来自动抓取所有文本文件并合并.
推荐答案
只要文件格式正确,它们是Windows(CRLF)ANSI文本文件,那么您可以考虑使用Type
?
As long as the files are properly formed Windows (CRLF) ANSI text files then you could consider using Type
?
Type *.txt>"..\Combined.txt"
此应该"写入当前目录的父目录中的Combined.txt
.我这样做是为了防止命令尝试读取其自身的内容,因为它也是一个.txt
文件. 如果愿意,可以用特定的路径替换"..\Combined.txt"
.
This 'should' write to Combined.txt
in the parent of the current directory. I have done this to prevent the command from trying to read it's own content, as it is also a .txt
file. Feel free to replace "..\Combined.txt"
with a specific path if you prefer.
如果您想要每个输出.txt
文件上方的文件名,请尝试将命令更改为此:
If you would like the file names above each output .txt
file then try changing the command to this:
Type *.txt>"..\Combined.txt" 2>&1
修改
另一个选项,该选项还应在文件名前加上
An additional option which also should prepend files with their names:
Find/V "" *.txt>"..\Combined.txt"
这篇关于如何将所有文本文件合并为带有断线的单个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!