Vb:如何选择多个文件目录?

时间:2014-04-18 16:41:47

标签: vb.net search directory

以下是代码:

 Try
        For Each strDir As String In
        System.IO.Directory.GetDirectories(My.Computer.FileSystem.SpecialDirectories.ProgramFiles)
            For Each strFile As String In System.IO.Directory.GetFiles(strDir)

               ListBox1.Items.Add(strFile)

            Next

        Next
    Catch ex As Exception
    End Try

问题出在哪里(My.Computer.FileSystem.SpecialDirectories.ProgramFiles)我想让它看到那里和那里:(My.Computer.FileSystem.SpecialDirectories.temp)

1 个答案:

答案 0 :(得分:0)

你必须分别循环每一个;你不能在一个电话中做到这一点。试试这个:

For Each strRootDir In {My.Computer.FileSystem.SpecialDirectories.ProgramFiles, My.Computer.FileSystem.SpecialDirectories.Temp}
    For Each strDir As String In System.IO.Directory.GetDirectories(strRootDir)
        For Each strFile As String In System.IO.Directory.GetFiles(strDir)
            ListBox1.Items.Add(strFile)
        Next
    Next
Next