I need to merge txt files into one txt file (they are in the same folder) in a command line. This works: for %f in (*.txt) do type "%f" >> output.txt
However I need name of each file before the content like: Name of file1 Content of file1 Name of file2 Content of file2 etc.
What is the code for the command line?
This works for me:
for %f in (*.txt) do echo %f >> output.txt & type %f >> output.txt
Note that output.txt will end up in the file as well, because once it's created it matches your *.txt
file mask. You may want to redirect to output.tmp
instead, and then after everything else is combined rename it.
# Linux
cat *.txt > all.txt