VB.NET 2005 General : How do I make my own Windows Explorer Application?

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

If you were to run this code now, your Treeview will show all the Folders and all the Subfolders within each folder, and all Sub folders within those etc..

Q: How do I list all the files within each folder also in the Treeview?

A: To list all the folders' files as well, simply add the following to the Treeview_AfterSelect event. Add this under the already existing If/End If structure:

Code:

Dim folder As String = CStr(e.Node.Tag)
If Not folder Is Nothing AndAlso IO.Directory.Exists(folder) Then
Try
For Each file As String In IO.Directory.GetFiles(folder)
e.Node.Nodes.Add(file.Substring(file.LastIndexOf("\"c) + 1))
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If

When a node is selected, the file names will also appear as sub nodes under the current selected node.

Q: What if I don't want the Filenames to appear in the Treeview, but in a ListView instead, what to do then?

A:

Add a ListView to your form, and name it. (with this FAQ, I kept the default names)

Remove the previous code (the code that added the Files) from the TreeView_AfterSelect event.

In Form_Load, add the following code, in order for us to have columns in our ListView:

Add the above code just underneath the already existing code, i.e, just above End Sub

Add the following code to the TreeView_AfterSelect event, to show the Folders' contents in the ListView. The code is almost exactly the same as our previous code in this event (The code to load the files into the Treeview)

Code:

Dim folder As String = CStr(TreeView1.SelectedNode.Tag)
If Not folder Is Nothing AndAlso IO.Directory.Exists(folder) Then
Try
For Each file As String In IO.Directory.GetFiles(folder)
ListView1.Items.Add(file.Substring(file.LastIndexOf("\"c) + 1), file.ToString())
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If

This will load all the files in the selected folder (selected node) into the ListView

Q: How do I add File Details such as The File Extension, and the Last Modified Date in the ListView?

A:

In the TreeView_AfterSelect event, declare the following 3(three) variables, just underneath the Private Sub statement: