• We just launched and are currently in beta. Join us as we build and grow the community.

Simple Way to Get All .txt Files in the Directory Using VB.Net

Nick Dudar

Automation Guru
N Rep
0
0
0
Rep
0
N Vouches
0
0
0
Vouches
0
Posts
193
Likes
32
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 100 XP
In this tutorial I’m going to teach you how to get all .txt Files in the Directory Using VB.Net. This method will surely help you to retrieve all .txt file in a specific directory and display it inside the listbox. This simple program can be easily done in no time. See the procedure below to find out how it works.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application in visual basic.
creating_vb_3.png

Step 2

Do the Form just like shown below.
2019-02-08_1.png

Step 3

Double click the form to fire the click event handler

of it and do the following code for getting all .txt file in a certain directory when the button is clicked.

  1. Private

    Sub

    Button1_Click(sender As

    Object

    , e As

    EventArgs) Handles Button1.Click
  2. Dim

    folderBrowseDialog As

    FolderBrowserDialog = New

    FolderBrowserDialog()
  3. folderBrowseDialog.SelectedPath = "C:\"
  4. Dim

    driNFO As

    New

    DirectoryInfo(folderBrowseDialog.SelectedPath)
  5. Dim

    txtFiles As

    FileInfo() = driNFO.GetFiles("*.txt"

    )
  6. ListBox1.Items.Clear()
  7. For

    Each

    txt_file As

    FileInfo In

    txtFiles
  8. ListBox1.Items.Add(txt_file.Name)
  9. Next
  10. End

    Sub

For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.

 

452,496

334,779

334,787

Top