Hi All,
I am currently creating a merging program which is processing multiple text files with header. I've manage to merge the text files but I'm stucked with the header that needs computation.
path of input files and header explanation: Input Files
After merging, I need to put back the header, adding up each values, which I explained in the path above. How can I do that?
Here's my current code:
Imports System.IO
Public Class Form1
Dim openFolder As New FolderBrowserDialog
'The routines must be
'1) Merge the txt file with the same version number number say all version 20, 23 and 13.
'2) Clean up the merged txt file by removing the unnecessary headers and adjusting number order form for merged txt file.
Private Sub btnMerge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMerge.Click
Try
openFolder.ShowDialog()
Dim dir As New DirectoryInfo(openFolder.SelectedPath)
Dim textFiles As FileInfo() = dir.GetFiles("*.txt")
Dim textFile As FileInfo
For Each textFile In textFiles
'System.IO.File.AppendAllText(openFolder.SelectedPath & "\merged.txt", System.IO.File.ReadAllText(openFolder.SelectedPath & "\" & textFile.ToString))
Call mergeV20(openFolder.SelectedPath & "\" & textFile.ToString)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
MessageBox.Show("Done!")
End Sub
Private Sub mergeV20(ByVal filepath As String)
Try
'reader declaration
Dim reader As StreamReader = New StreamReader(filepath)
Dim writer As New StreamWriter(openFolder.SelectedPath & "\merged.txt", True)
'get filename from full path
Dim intPos As Integer
intPos = filepath.LastIndexOfAny("\")
intPos += 1
Dim fileName As String = filepath.Substring(intPos, (Len(filepath) - intPos))
Dim fileFpath As String = filepath.Substring(0, intPos)
Dim fileCount As Integer = Directory.GetFiles(fileFpath, "*.txt").Length
'end get filename from full path
'start of merging function
'start header part
reader.ReadLine()
While Not reader.EndOfStream
Dim oLines As String = reader.ReadLine()
writer.WriteLine(oLines, True)
End While
'end header part
writer.Close()
writer.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Thanks in advance.