I want to merge the content of multiple text files to one text file.
I've tried cat
explained in this answer. But it is very slow.
The copy
command is much faster but you have to put the filenames in a plus sign separated string like:
cmd /c copy file1.txt + file2.txt + file3.txt + file1.txt all.txt
It is ok for a few files, but not for thousands of files.
So my idea was to create a variable that contains the file input for copy
like:
%list = 'file1.txt + file2.txt + file3.txt + file1.txt'
and then:
cmd /c copy %list all.txt
But this doesn't work.
(I can create the string with the filenames also within Powershell with a loop.)
Now I want to make a loop that merges the first file with the second file and the resulting file with the third file and so on.
cmd /c copy file1.txt + file2.txt merge1.txt
then:
cmd /c copy merge1.txt + file3.txt merge2.txt
...
How can I do this within a loop in Powershell?