devxlogo

ConcatenateFiles – Concatenating multiple text files

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:
es.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 TryEnd Sub

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist