Merge many TXT files into one (and include the filenames)??? (TXTcollector quit working...)

krs000a

Honorable
Mar 29, 2013
60
0
10,630
Hello,
I've been searching for 3 hours now, and finally I give up and have to ask for help.

This is what I want to do.

* Merge all *.txt files within a folder into one text file.

* In the new document, the content of each file should be introduced with its filename.
Example:

TEXT FILE 1.TXT contents:
one
two
three

TEXT FILE 2.TXT contents:
four
five
six

Combined file should look something like this:

TEXT FILE 1.TXT
one
two
three

TEXT FILE 2.TXT
four
five
six

I have been using TXTcollector, an excellent software that is available as freeware at http://bluefive.pair.com. This software did exactly what I wanted, and even included an optional line seperator (*************) between each original file listed in the combined text file. However, all of a sudden, the software quit working and it will only include (randomly selected) text files, rest of them it tells me "[Error] the file could not be written". I have tried it on two different computers (one Win7, one Vista) and same result on both. I can't write the maker of the program as he has removed his e-mail from the website.
So, are there any other softwares that will do what I want? Please note like I explained earlier that it's crucial that each file's original filename is also included in the merged file, before its content, so I know which text file each content originated from.
 
Solution
@echo off
for /r %%i in (*.txt) do (
if not %%~nxi == output.txt (
echo %%~nxi >> output.txt
type "%%i" >> output.txt
echo. >> output.txt
echo =================================================================== >> output.txt
)
)

Sylvvester

Distinguished
Nov 22, 2010
160
0
18,760
You can do it with a simple batch script. Just save this in a txt file, change extension to .bat and run it:

@echo off
for /r %%i in (*.txt) do (
if not %%~nxi == output.txt (
echo %%~nxi >> output.txt
type "%%i" >> output.txt
echo. >> output.txt
echo. >> output.txt
)
)
 

krs000a

Honorable
Mar 29, 2013
60
0
10,630
Your solution works great - thank you! One more thing, would it be possible to add a line between each text file input, something to make it more clear where there is a new text in the final output.txt?
Something like a line of === between each text file that it merged, like this:
================================================
 

Sylvvester

Distinguished
Nov 22, 2010
160
0
18,760
@echo off
for /r %%i in (*.txt) do (
if not %%~nxi == output.txt (
echo %%~nxi >> output.txt
type "%%i" >> output.txt
echo. >> output.txt
echo =================================================================== >> output.txt
)
)
 
Solution