1
Hi! What I would like is to display Windows directories on a ListBox
. In my Form
I have a button just above the ListBox
that serves to return (previous directory) and the event SelectedIndexChanged
to take the path that is being clicked on ListBox
.
Load:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
claForm.abcd("C:\...\Filmes")
End Sub
Button:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
claForm.abcd(ClaForm.claTeste.PrevFolder1)
End Sub
Selectedindexchanged
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
claForm.abcd(ClaForm.claTeste.Subfolder1(ListBox1.SelectedItem))
End Sub
sub:
Dim claTeste As ClaListBoxOrder 'Indica o caminho atual mostrado no listbox. Nela contem: pasta anterior, pasta atual, pastas que estão dentro dela
Public Sub abcd(ByVal diretorio As String)
ListBox1.Items.Clear()
Dim path() As String = System.IO.Directory.GetDirectories(diretorio)
If path.Length = 0 Then
Return
Else
'Salva pasta que esta aberta no listbox
Dim Dos As New DirectoryInfo(diretorio) 'pega o nome da pasta para aparecer no Listbox Ex: C:/.../nova pasta/ Coisas == Coisas
claTeste = New ClaListBoxOrder
claTeste.Folder1 = diretorio
claTeste.PrevFolder1 = Left(diretorio, Len(diretorio) - Len(Dos.Name) - 1)
For Each folder In path
'Algumas verificações para ver se a pasta será exibida
If FileIO.FileSystem.GetFiles(folder, FileIO.SearchOption.SearchAllSubDirectories, "*.mp4", "*.avi", "*.wmv", "*.mkv").Count > 1 Then
If FileIO.FileSystem.GetFiles(folder, FileIO.SearchOption.SearchAllSubDirectories, "*.mp4", "*.avi", "*.wmv", "*.mkv").Count > 0 Then
' Carrega listbox com o nome da pasta
Dim Di As New DirectoryInfo(folder)
ListBox1.Items.Add(Di.Name)
'dicionario nome que está no listbox, caminh dele
claTeste.Subfolder1.Add(Di.Name, folder)
End If
'Algumas verificações para ver se a pasta será exibida
ElseIf FileIO.FileSystem.GetDirectories(folder, FileIO.SearchOption.SearchTopLevelOnly).Count > 0 Then 'pega pastas que tem outras pastas dentro com 1 arquivo de video só
For Each files In FileIO.FileSystem.GetDirectories(folder, FileIO.SearchOption.SearchAllSubDirectories)
If FileIO.FileSystem.GetFiles(files, FileIO.SearchOption.SearchAllSubDirectories, "*.mp4", "*.avi", "*.wmv", "*.mkv").Count > 0 Then
If FileIO.FileSystem.GetFiles(folder, FileIO.SearchOption.SearchAllSubDirectories, "*.mp4", "*.avi", "*.wmv", "*.mkv").Count > 0 Then
' Carrega listbox com o nome da pasta
Dim Di As New DirectoryInfo(folder)
ListBox1.Items.Add(Di.Name)
'dicionario nome que está no listbox, caminh dele
claTeste.Subfolder1.Add(Di.Name, folder)
End If
Exit For
End If
Next
End If
Next
End If
End Sub
This code is working the way I want it to, but it’s where it’s at, which is whenever I click on something Listbox
it will perform all the checks. The problem is that in some cases when it has many folders this scan takes time. I tried some ways to save data from all folders and subfolders in the program to just order later, but I had problems with repeated folder names, for example the name of the folder that is in the Listbox
is "Things", but there are 2 different folder paths that also has the name "Cosias".
In other words, what I want is to browse the Windows directories, displaying only folders in Listbox following some rules. If anyone can help with a solution thank you, just remembering that I do not want to use the Treeview
.