Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

ConcatenateFiles - Concatenating multiple text files

Total Hit ( 2828)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
' 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


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.