Hi everyone,

I would like to merge few text documents into one,
For example, i have 12 text documents in a folder,
then needed to merge their text into one. 12 = 1.
any help will be very appreciate, thanks in advance.

if is not much to ask, if i can't do this
using Visual Basic 6, will be nice if some one can
tell me how to accomplish this using batch script.
thank you again.

See if this help.
This following code will merge multiple text files into one file :
Add reference : Microsoft Scripting Runtime

Private Sub ConcatenateFiles(ByVal ResultFile As String, ByVal Separator As String, ParamArray SourceFiles() As Variant)
    Dim FSO As New FileSystemObject
    Dim fsSourceStream As TextStream
    Dim fsResStream As TextStream
    Dim sSeparator As String
    Dim i As Integer
    On Error Resume Next
    ' create a new file
    Set fsResStream = FSO.OpenTextFile(ResultFile, ForWriting, True)
    ' for each source file in the input array
    For i = 0 To UBound(SourceFiles)
        ' add the separator first (replacing the special tag for the file path)
        sSeparator = Replace(Separator, "#FilePath#", SourceFiles(i))
        fsResStream.Write sSeparator & vbCrLf
        ' open the file in read mode
        Set fsSourceStream = FSO.OpenTextFile(SourceFiles(i), ForReading)
        ' add its content + a blank line to the result file
        fsResStream.Write fsSourceStream.ReadAll & vbCrLf
        ' close this source file
    Next i
End Sub

Private Sub Command1_Click()
' Example:
 ConcatenateFiles "D:\res.txt", "------ NEW FILE: #FilePath# ------", "D:\1.txt", "D:\2.txt", "D:\3.txt"
End Sub
Absolutely Help
This is an awosome code :)

Thank You So Much JX :-) Just what i need it !!!!
What i nice little piece of code, thanks a lot :-)

Private Sub Command1_Click()
ConcatenateFiles "All-In-One.txt", "=======================================", "1.txt", "2.txt", "3.txt"
End Sub
This question has already been answered. Start a new discussion instead.