将扩展名排除添加到列表框

时间:2018-04-11 02:25:31

标签: vb.net

我有一些代码,我正在使用TextBox的值并将其用作io.directoryInfo。它需要提供的信息并将其添加到列表框中。以及基本文件夹名称。我想将此限制为仅接受.avi,.mp4和.wmv文件类型。有人可以帮忙吗?

Private Sub ButtonOk_Click(sender As Object, e As EventArgs) Handles ButtonOk.Click

    Dim BaseFolder As New IO.DirectoryInfo(TextBoxFolderLocation.Text)
    For Each f As IO.DirectoryInfo In BaseFolder.GetDirectories()
        AddContents(f)
    Next
End Sub

Sub AddContents(ByVal BaseFolder As IO.DirectoryInfo)
    ListBox1.Items.AddRange((From FI As IO.FileInfo In BaseFolder.GetFiles Select FI.Name).ToArray)
    For Each subF As IO.DirectoryInfo In BaseFolder.GetDirectories()
        Application.DoEvents()
        ListBox1.Items.Add("[" & BaseFolder.Name & "]")
        AddContents(subF)
    Next
End Sub

0 个答案:

没有答案