Simple Way to Get All .txt Files in the Directory Using VB.Net
Submitted by janobe on Friday, February 8, 2019 - 21:56.
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.
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.
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.
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim folderBrowseDialog As FolderBrowserDialog = New FolderBrowserDialog()
- folderBrowseDialog.SelectedPath = "C:\"
- Dim driNFO As New DirectoryInfo(folderBrowseDialog.SelectedPath)
- Dim txtFiles As FileInfo() = driNFO.GetFiles("*.txt")
- ListBox1.Items.Clear()
- For Each txt_file As FileInfo In txtFiles
- ListBox1.Items.Add(txt_file.Name)
- Next
- End Sub
Add new comment
- 820 views