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

Submitted by: 
Visitors have accessed this post 260 times.

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.

Step 2

Do the Form just like shown below.

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.

  2. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  3. Dim folderBrowseDialog As FolderBrowserDialog = New FolderBrowserDialog()
  4. folderBrowseDialog.SelectedPath = "C:\"
  5. Dim driNFO As New DirectoryInfo(folderBrowseDialog.SelectedPath)
  6. Dim txtFiles As FileInfo() = driNFO.GetFiles("*.txt")
  7. ListBox1.Items.Clear()
  8. For Each txt_file As FileInfo In txtFiles
  9. ListBox1.Items.Add(txt_file.Name)
  10. Next
  11. 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.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.