locked
Compile text files into a single file RRS feed

  • Question


  • I have a set of text files that are not limited to one folder (d:\textfil)
    I want to create a new text file from them
    Passes all the files in order to take the data from the first file to the last without repeating the similar lynn where each file may contain latin
    It puts new data down the old

    1

    Saturday, February 17, 2018 6:31 PM

Answers

  • Hi

    Here is some code to do as per the above information. Note: no error checking included. This code DOES work OK here.

    Option Strict On
    Option Explicit On
    Public Class Form1
      'make your own paths here
      Dim SourcePath As String = "C:\Users\lesha\Desktop\Plans\New folder\TextFil"
      Dim DestPath As String = "C:\Users\lesha\Desktop\Combined.txt"
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	Dim lst As New List(Of String)
    	For Each f As String In IO.Directory.GetFiles(SourcePath, "*.txt", IO.SearchOption.TopDirectoryOnly)
    	  Dim lst2 As List(Of String) = IO.File.ReadAllLines(f).ToList
    	  For Each s As String In lst2
    		If Not lst.Contains(s) Then
    		  lst.Add(s)
    		End If
    	  Next
    	Next
    	IO.File.WriteAllLines(DestPath, lst.ToArray)
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by monemas Saturday, February 17, 2018 8:46 PM
    Saturday, February 17, 2018 8:23 PM

All replies

  • Hi

    You say the set of files are NOT limited to one folder - so, do you need to select a series of folders?

    Do subfolders get included?

    *

    Please confirm if this is correct:

    1. you need the user to select one or more folders (subfolders included).

    2. create a new text file and copy the text from ALL of the text files contained in the selected folders - without copying lines which are already in the new file.


    Regards Les, Livingston, Scotland

    Saturday, February 17, 2018 6:56 PM
  • Hi

    You say the set of files are NOT limited to one folder - so, do you need to select a series of folders?

    Do subfolders get included?

    *

    Please confirm if this is correct:

    1. you need the user to select one or more folders (subfolders included).

    2. create a new text file and copy the text from ALL of the text files contained in the selected folders - without copying lines which are already in the new file.


    Regards Les, Livingston, Scotland

    1- no subfolders included

    only folder  (d:\textfil)

    2- yes


    • Edited by monemas Saturday, February 17, 2018 7:11 PM
    Saturday, February 17, 2018 7:09 PM
  • Hi

    Here is some code to do as per the above information. Note: no error checking included. This code DOES work OK here.

    Option Strict On
    Option Explicit On
    Public Class Form1
      'make your own paths here
      Dim SourcePath As String = "C:\Users\lesha\Desktop\Plans\New folder\TextFil"
      Dim DestPath As String = "C:\Users\lesha\Desktop\Combined.txt"
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	Dim lst As New List(Of String)
    	For Each f As String In IO.Directory.GetFiles(SourcePath, "*.txt", IO.SearchOption.TopDirectoryOnly)
    	  Dim lst2 As List(Of String) = IO.File.ReadAllLines(f).ToList
    	  For Each s As String In lst2
    		If Not lst.Contains(s) Then
    		  lst.Add(s)
    		End If
    	  Next
    	Next
    	IO.File.WriteAllLines(DestPath, lst.ToArray)
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by monemas Saturday, February 17, 2018 8:46 PM
    Saturday, February 17, 2018 8:23 PM
  • Hi

    Here is some code to do as per the above information. Note: no error checking included. This code DOES work OK here.

    Option Strict On
    Option Explicit On
    Public Class Form1
      'make your own paths here
      Dim SourcePath As String = "C:\Users\lesha\Desktop\Plans\New folder\TextFil"
      Dim DestPath As String = "C:\Users\lesha\Desktop\Combined.txt"
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	Dim lst As New List(Of String)
    	For Each f As String In IO.Directory.GetFiles(SourcePath, "*.txt", IO.SearchOption.TopDirectoryOnly)
    	  Dim lst2 As List(Of String) = IO.File.ReadAllLines(f).ToList
    	  For Each s As String In lst2
    		If Not lst.Contains(s) Then
    		  lst.Add(s)
    		End If
    	  Next
    	Next
    	IO.File.WriteAllLines(DestPath, lst.ToArray)
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    You are a creative person
    Saturday, February 17, 2018 8:44 PM