DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   merging two txt files into one txt file (http://www.daniweb.com/forums/thread166200.html)

nmakkena Jan 5th, 2009 7:35 am
merging two txt files into one txt file
 
Hi,

Actully i wanted to merge two txt files into one txt file. (i.e. second file has to be appended to the first file). please give me some solution for my problem. I am new to vb.net, so pls elaborate the solution.

Thanks in advance.

robert_c_guy Jan 5th, 2009 9:03 am
Re: merging two txt files into one txt file
 
VB.Net makes a task like that quite simple:
    Public Sub text_combine( _
        ByVal path_to_read_file As String, _
        ByVal path_to_append_file As String _
    )
        System.IO.File.AppendAllText( _
            path_to_append_file, _
            System.IO.File.ReadAllText(path_to_read_file) _
        )
    End Sub
A little error checking may prevent hangups:
    Public Function text_combine( _
        ByVal path_to_read_file As String, _
        ByVal path_to_append_file As String _
    ) As Boolean
        If ( _
            (IO.File.Exists(path_to_read_file)) _
            And (IO.File.Exists(path_to_append_file)) _
        ) Then
            Try
                System.IO.File.AppendAllText( _
                    path_to_append_file, _
                    System.IO.File.ReadAllText(path_to_read_file) _
                )
                text_combine = True
            Catch ex As Exception
                text_combine = False
            End Try
        Else
            text_combine = False
        End If
    End Function


All times are GMT -4. The time now is 8:59 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC