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

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. ps1

Step 2

Do the Form just like shown below. ps2

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.  
  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