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
Private Sub Command1_Click()
ConcatenateFiles "D:\res.txt", "------ NEW FILE: #FilePath# ------", "D:\1.txt", "D:\2.txt", "D:\3.txt"
#define A 3// name a constant
long int booking_ID ; ...