繁体   English   中英

如何使用 vb.net (Visual Studio 2012 Express) 从驱动器中获取可访问的文件夹名称

[英]how to get the accessible folder names from a drive with vb.net (Visual Studio 2012 Express)

我正在尝试为一位朋友创建一个程序,该程序允许他“整理”并找到他的文件。
他有几个驱动器和许多文件夹。 我想为他做的是:

  1. 具有在组合框中列出所有活动驱动器的代码。 然后,他可以选择要搜索的驱动器,以按扩展名搜索任何或仅选定的文件类型。

  2. 然后他要么选择“一切”,要么选择特定类型(即:音乐)

  3. 单击按钮后,列表框将填充文件的完整路径

开始这个写作过程,我已经完成了这个:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Button1.Enabled = False

    Dim allDrives() As DriveInfo = DriveInfo.GetDrives()

    Dim d As DriveInfo
    For Each d In allDrives
        If d.IsReady Then ComboBox1.Items.Add(d)
    Next

End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged

    If ComboBox1.SelectedIndex <> -1 Then

        Try

            For Each DName As String In My.Computer.FileSystem.GetDirectories(ComboBox1.Text, FileIO.SearchOption.SearchTopLevelOnly)
                Dim LDN As Integer = Len(DName)
                Dim FName As String = Strings.Mid(DName, 4, LDN - 3)
                CheckedListBox1.Items.Add(FName, False)
            Next

        Catch ex As Exception

        End Try

    Else
        Exit Sub
    End If

End Sub

我的第一个问题是 GetDirectories 进程正在获取我知道我无权访问的目录。 我试图弄清楚如何防止这种情况。 谁能帮我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM