How to Merge all Text files in a Single file with Broken Lines?

≯℡__Kan透↙ 提交于 2019-12-25 00:13:50

问题


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

When it ends it, he stay like this:

abcblue

123abcyellow

123abc

When I expected it to go like this:

ABC

blue

123

abc

yellow

123

abc

Whats wrong?

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

In this context:

type file1.txt >> newfile.txt
echo. >> newfile.txt
type file2.txt >> newfile.txt
echo. >> newfile.txt
type file3.txt >> newfile.txt
echo. >> newfile.txt

But I need it to automatically grab all text files and combine.


回答1:


As long as the files are properly formed Windows (CRLF) ANSI text files then you could consider using Type?

Type *.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.

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

Edit

An additional option which also should prepend files with their names:

Find/V "" *.txt>"..\Combined.txt"


来源:https://stackoverflow.com/questions/46444302/how-to-merge-all-text-files-in-a-single-file-with-broken-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!