Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7079033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:37:16+00:00 2026-05-28T06:37:16+00:00

I have a folder that contains about 100 txt files with information in each

  • 0

I have a folder that contains about 100 txt files with information in each file.

I’m trying to figure out how to loop through each file in the folder, and add the text to a string.

I’ve pulled this off MSDN’s site, but it doesn’t seem to read “each” file but just one.

Any ideas on how to read each file in a folder and add the text to a string? thanks

    Dim path As String = "c:\temp\MyTest.txt"

    ' This text is added only once to the file.
    If File.Exists(path) = False Then

        ' Create a file to write to.
        Dim createText As String = "Hello and Welcome" + Environment.NewLine
        File.WriteAllText(path, createText)
    End If

    ' This text is always added, making the file longer over time
    ' if it is not deleted.
    Dim appendText As String = "This is extra text" + Environment.NewLine
    File.AppendAllText(path, appendText)

    ' Open the file to read from.
    Dim readText As String = File.ReadAllText(path)
    RichTextBox1.Text = (readText)

This just gives me the text they created and not anything from the txt files.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:37:17+00:00Added an answer on May 28, 2026 at 6:37 am

    What you’ll want to do is loop through the files using the DirectoryInfo.GetFiles() method. Here’s an example, which also uses a StringBuilder for better performance:

    Dim fileContents As New System.Text.StringBuilder()
    
    For Each f As FileInfo In New DirectoryInfo("C:\MyFolder").GetFiles("*.txt") ' Specify a file pattern here
        fileContents.Append(File.ReadAllText(f.FullName))
    Next
    
    ' Now you can access all the contents using fileContents.ToString()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following: Folder that contains many files (about 300000), named AllFilesFolder list
I have a zip file that contains folder hierarchies and files. \images\ \images\1.jpg \images\2.jpg
I have a folder that contains many different files: folder1: somthing.php somthingelse.php blah.php ect
I have a folder X:/EmpInfo that contains many different folders. Each of these folders
I have a folder that contains more than 200K images. Some images will follow
I have a folder \folder\ above the webroot that contains .php , .inc ,
Suppose i have one folder and inside that another two files are there .
I have a C# project that contains 1 EXE and about 7 DLLs. What
I have been reading about the function of __init__.py file. It is said that
Specifically, I have a folder structure that looks like the below: about (main folder)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.