将目录中所有*.txt文件合并为一个大文本文件的最快和最实用的方法是什么?

目前我正在使用cygwin的窗口,所以我可以访问BASH。

Windows shell命令也会很好,但我怀疑有没有一个。


当前回答

type [source folder]\*.[File extension] > [destination folder]\[file name].[File extension]

例如:

type C:\*.txt > C:\1\all.txt

这将采取所有的txt文件在C:\文件夹,并将其保存在C:\1文件夹的名称为all.txt

Or

type [source folder]\* > [destination folder]\[file name].[File extension]

例如:

type C:\* > C:\1\all.txt

这将获取文件夹中所有文件,并将Content放在C:\1\all.txt中

其他回答

这会将输出追加到all.txt

cat *.txt >> all.txt

这将覆盖all.txt

cat *.txt > all.txt

请记住,对于目前给出的所有解决方案,shell决定文件连接的顺序。巴什,IIRC,这是字母顺序。如果顺序很重要,您应该适当地命名这些文件(01file.txt, 02file.txt,等等),或者按照您想要连接的顺序指定每个文件。

$ cat file1 file2 file3 file4 file5 file6 > out.txt

这种方法怎么样?

find . -type f -name '*.txt' -exec cat {} + >> output.txt
type [source folder]\*.[File extension] > [destination folder]\[file name].[File extension]

例如:

type C:\*.txt > C:\1\all.txt

这将采取所有的txt文件在C:\文件夹,并将其保存在C:\1文件夹的名称为all.txt

Or

type [source folder]\* > [destination folder]\[file name].[File extension]

例如:

type C:\* > C:\1\all.txt

这将获取文件夹中所有文件,并将Content放在C:\1\all.txt中

你可以这样做: 猫(directory_path) / * * / *。[h,m] > test.txt

如果使用{}包含要查找的文件的扩展名,则存在顺序问题。