Good day, I need some assistance here, I am trying to create my own simple file explorer, in my form I have a Listview and a Combobox and I have these codes below.
In my form load I have this code to list in comobobox all the existing folders in my current directory.
Dim dir As New DirectoryInfo(Environment.CurrentDirectory & "\")
Dim dirarr As DirectoryInfo() = dir.GetDirectories()
Dim directinfo As DirectoryInfo
For Each directinfo In dirarr
ListView1.Items.Add(directinfo.Name)
Next directinfo
While in my combobox selectedindex event I have this
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ListView1.Items.Count = 0 Then
filesinfolder()
Else
ListView1.Items.Clear()
filesinfolder()
End If
End Sub
I have a sub called filesinfolder
Sub filesinfolder()
Try
Dim mb As Double = 1048576 + 1
Dim di As New IO.DirectoryInfo(Environment.CurrentDirectory & "\" & ComboBox1.Text)
Dim aryFi As IO.FileInfo() = di.GetFiles("*")
Dim fi As IO.FileInfo
Dim lv As ListViewItem
Dim filesize As Double
Dim fileformat As Double
Dim dir As New DirectoryInfo(Environment.CurrentDirectory & "\" & Combobox1.Text)
Dim dirarr As DirectoryInfo() = dir.GetDirectories()
Dim directinfo As DirectoryInfo
For Each directinfo In diArr
ListView1.Items.Add(directinfo.Name)
Next directinfo
For Each fi In aryFi
filesize = fi.Length / mb
fileformat = Format(filesize, "#,##0.00")
lv = ListView1.Items.Add(fi.Name)
lv.SubItems.Add(fileformat)
lv.SubItems.Add(fi.Extension)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
The sub above list all the files and subfolders that is selected from the combobox, but what I want is to access the files in subfolders and sub-subfolders and so on by simply double clicking the folder name. How can I possibly do that? I tried to include the directoryinfo in listview doubleclick event but it only gives me an error that it is inaccessible. All works fine and I can open the files but I cannot access files in subfolders and so on. Or how can I include the subfolders and other folders inside a subfolder (if any) in my combobox? So that when I select a folder name all files beneath will be shown in my listview. Any idea? Thanks in advance


1Likes
LinkBack URL
About LinkBacks




Reply With Quote




Bookmarks