Even though you have an accepted solution that is done with LINQ when dealing with files that may not be in a specific format or something unknown happens the one line solution should be replaced with one that provides exception handling along with utilizing (in this case) an interface for custom sorting, TextFieldParser for reading files into a list via a Sorted set that implements the custom IComparer interface.
In the code sample I take three files, combine into one then export to a new file. A DataGridView provides confirmation the results are correct prior to exporting.
Note sorting is done on product name
in this code sample
Implmentation form code
Public Class Form1
Private Sub CombineFilesButton_Click(sender As Object, e As EventArgs) Handles CombineFilesButton.Click
DataGridView1.DataSource = Nothing
ExportListButton.Enabled = False
Dim products = FileOperations.Read()
If products.Count > 0 Then
DataGridView1.DataSource = products
ExportListButton.Enabled = True
End If
End Sub
Private Sub ExportListButton_Click(sender As Object, e As EventArgs) Handles ExportListButton.Click
If DataGridView1.DataSource IsNot Nothing Then
FileOperations.Export(CType(DataGridView1.DataSource, List(Of Product)))
End If
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
AddHandler FileOperations.ExceptionHandler, AddressOf GeneralExceptionWhileReadingFile
AddHandler FileOperations.MalformedLineExceptionHandler, AddressOf MalFormExceptionWhileReadingFile
ExportListButton.Enabled = False
End Sub
Private Sub MalFormExceptionWhileReadingFile(exception As Microsoft.VisualBasic.FileIO.MalformedLineException, fileName As String)
Console.WriteLine($"Read error on line {exception.LineNumber} with file {fileName}")
End Sub
Private Sub GeneralExceptionWhileReadingFile(exception As Exception, fileName As String)
Console.WriteLine($"General error: {exception.Message} with file {fileName}")
End Sub
End Class