Dim ext As String = "*.*"
Dim listOfExts As New ArrayList
For Each filename As String In My.Computer.FileSystem.GetFiles(FolderBrowserDialog1.SelectedPath, _
FileIO.SearchOption.SearchTopLevelOnly, ext)
ext = Path.GetExtension(filename).ToUpper
If Not listOfExts.Contains(ext) Then
listOfExts.Add(ext)
End If
Next
listOfExts.Sort()
CboExtensions.DataSource = listOfExts
lblTotalItems.Text = txtBoxFiles.Lines.Length
End Sub
Private Sub btnSelectFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnSelectFolder.Click
If Me.FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim extList As New List(Of String)
Me.ComboBox1.Items.Clear()
Me.ListBox1.Items.Clear()
Dim di As New IO.DirectoryInfo(Me.FolderBrowserDialog1.SelectedPath)
Me.ListBox1.Items.AddRange(di.GetFiles())
For Each fi As IO.FileInfo In di.GetFiles()
If Not extList.Contains(fi.Extension) Then
extList.Add(fi.Extension)
End If
Next
Me.ComboBox1.Items.Add("*.*")
Me.ComboBox1.Items.AddRange(extList.ToArray())
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ComboBox1.SelectedIndexChanged
Dim di As New IO.DirectoryInfo(Me.FolderBrowserDialog1.SelectedPath)
Me.ListBox1.Items.Clear()
Me.ListBox1.Items.AddRange(di.GetFiles("*" & Me.ComboBox1.SelectedItem))
End Sub
Dim fileList As List(Of String)
Private Sub btnSelectFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnSelectFolder.Click
If Me.FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim extList As New List(Of String)
fileList = New List(Of String)
Me.ComboBox1.Items.Clear()
Me.ListBox1.Items.Clear()
Dim di As New IO.DirectoryInfo(Me.FolderBrowserDialog1.SelectedPath)
For Each fi As IO.FileInfo In di.GetFiles()
fileList.Add(fi.Name())
If Not extList.Contains(fi.Extension.ToLower()) Then
extList.Add(fi.Extension.ToLower())
End If
extList.Sort()
Next
Me.ComboBox1.Items.Add("*.*")
Me.ComboBox1.Items.AddRange(extList.ToArray())
Me.ComboBox1.SelectedItem = 0
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ComboBox1.SelectedIndexChanged
Me.ListBox1.Items.Clear()
Dim filteredList As List(Of String) = fileList.FindAll(AddressOf SelectedExtension)
If Me.ComboBox1.SelectedItem = "*.*" Then
Me.ListBox1.Items.AddRange(fileList.ToArray())
Else
Me.ListBox1.Items.AddRange(filteredList.ToArray())
End If
End Sub
Private Function SelectedExtension(ByVal s As String) As Boolean
Dim fi As New IO.FileInfo(s)
Return fi.Extension = Me.ComboBox1.SelectedItem
End Function