How to Browse Computer Drives Using VB.Net

Submitted by: 
Visitors have accessed this post 220 times.

Now, let’s learn how to browse computer drives using VB.Net. The function of this program is to browse the entire folder inside your computer drive. In this way you can also view list of files inside the folder of computer drives. You will see it because it will be displayed inside the listbox. Now let’s begin.

Creating Application

Step 1

Open Visual Studio 2015 and create a new windows form application.
bdrives123

Step 2

Do the form just like this.
bdrive321

Step 3

Double click the Form and do the following codes to display all drives in the first load of the form.

  1. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  2. For Each dri As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives
  3. ListBox1.Items.Add(dri)
  4. Next
  5. End Sub

Step 4

Double click the ListBox1 and do the following codes to display the entire folder inside the drive.

  1. Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
  2. ListBox2.Items.Clear()
  3. Try
  4. Dim dri As System.IO.DriveInfo = DirectCast(ListBox1.SelectedItem, System.IO.DriveInfo)
  5.  
  6. For Each dirInfo As System.IO.DirectoryInfo In dri.RootDirectory.GetDirectories()
  7. ListBox2.Items.Add(dirInfo)
  8. Next
  9. Catch ex As Exception
  10. MsgBox(ex.Message)
  11. End Try
  12. End Sub

Step 5

Double click the ListBox2 and do the following codes to display all files inside the folder.

  1. Private Sub ListBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox2.SelectedIndexChanged
  2. ListBox3.Items.Clear()
  3. Try
  4. Dim dirinfo As System.IO.DirectoryInfo = DirectCast(ListBox2.SelectedItem, System.IO.DirectoryInfo)
  5. For Each f As System.IO.FileInfo In dirinfo.GetFiles()
  6. ListBox3.Items.Add(f)
  7. Next
  8. Catch ex As Exception
  9. MsgBox(ex.Message)
  10. End Try
  11. End Sub

For more question about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
FB Account – https://www.facebook.com/onnaj.soicalap
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.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.