dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB7
Expertise: Intermediate
Apr 14, 2003

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


ConcatenateFiles - Concatenating multiple text files

' Concatenate a variable number of text files into a single result file
'
' Params:
'  - resultFile: the complete path of the result file you want to create
'  - header: a string that is written when a file is added to the result file.
'    Note: this string can contain the #FilePath# tag that will be replaced 
' with the path of the file being added
'  - sourceFiles: the sequence of files whose content will be concatenated
'
' Example:
'   ConcatenateFiles ("D:\res.txt", "------ NEW FILE: #FilePath# ------",
'  "D:\1.txt", "D:\2.txt", "D:\3.txt")

Sub ConcatenateFiles(ByVal resultFile As String, ByVal header As String, _
    ByVal ParamArray sourceFiles() As String)
    Dim writer As System.IO.StreamWriter
    Dim reader As System.IO.StreamReader

    Try
        writer = New System.IO.StreamWriter(resultFile, True)
        Dim fpath As String
        For Each fpath In sourceFiles
            ' write the header string, with #FilePath# replaced with
            ' the path of the source file being processed
            writer.WriteLine(header.Replace("#FilePath#", fpath))
            Try
                ' open the source file in read mode
                reader = New System.IO.StreamReader(fpath)
                ' append all the content of the current file in the destination 
                ' file
                writer.Write(reader.ReadToEnd() & Environment.NewLine)
            Finally
                If Not reader Is Nothing Then
                    reader.Close()
                    reader = Nothing
                End If
            End Try
        Next
    Finally
        ' close the writer stream
        If Not writer Is Nothing Then writer.Close()
    End Try
End Sub
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date