Results 1 to 4 of 4

Thread: [RESOLVED] vb.net combine multiple text files

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2021
    Posts
    178

    Resolved [RESOLVED] vb.net combine multiple text files

    Hi All... I am using this code to combine text files. How can I add a carriage return after each file?

    I need this output:

    Code:
    Apple
    Banana
    Orange
    Not like this code is doing:

    Code:
    AppleBananaOrange
    Code:
    Imports System.IO
    Imports System.Text
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim newDateFormat As String
            newDateFormat = DateTime.Now.ToString("MM.dd.yyyy_mm.HH.ss")
            Dim prgPath As String = IO.Path.GetDirectoryName(Application.ExecutablePath)
    
            Dim Paths() As String = Directory.GetFiles(prgPath, "*.txt")
            For Each Path As String In Paths
                File.AppendAllText("Combined_" & newDateFormat & ".txt", File.ReadAllText(Path), Encoding.Default)
            Next
    
    
    
        End Sub
    End Class

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: vb.net combine multiple text files

    Use AppendAllLines and ReadAllLines instead.
    Code:
    File.AppendAllLines($"Combined_{DateTime.Now:MM.dd.yyyy_mm.HH.ss}.txt", File.ReadAllLines(Path), Encoding.Default)
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2021
    Posts
    178

    Re: vb.net combine multiple text files

    works great! Thank You dday9

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: vb.net combine multiple text files

    If your issue is resolved, please use the Thread Tools menu to mark the thread Resolved so that we don't have to open it and read the whole thing to find out that you no longer need help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width