vb.net |如何在指定的路径中获取空子目录?使用vb.net

时间:2015-12-26 13:44:56

标签: vb.net directory directoryinfo getdirectories

我的目录结构如下所示。

  • dir1> subdir1_1>((subdir1_1_1> subdir1_1_1_1),subdir1_1_2)
  • DIR2

    拖曳主目录和subdir1_1有2个子目录(subdir1_1_1,subdir1_1_2)和subdir1_1_1有子目录" subdir1_1_1_1"

好的

现在我有了这段代码

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim BaseFolder As New IO.DirectoryInfo(Me.TextBox1.Text)

        For Each f As IO.DirectoryInfo In BaseFolder.GetDirectories()
            AddContents(f)
        Next
    End Sub
    Sub AddContents(ByVal BaseFolder As IO.DirectoryInfo)


        For Each subF As IO.DirectoryInfo In BaseFolder.GetDirectories()


            ListBox1.Items.Add(BaseFolder.FullName)

            AddContents(subF)
        Next
    End Sub
End Class

和我的textbox1.text =" C:\ test"

,结果没有subdir1_1_1_1和subdir1_1_2。为什么??

问题在哪里?为什么我无法获取空文件夹? enter image description here

1 个答案:

答案 0 :(得分:1)

以这种方式试试

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim BaseFolder As New IO.DirectoryInfo(Me.TextBox1.Text)
    ListBox1.Items.Clear()
    AddContents(BaseFolder)
End Sub

Sub AddContents(ByVal BaseFolder As IO.DirectoryInfo)
    ListBox1.Items.Add(BaseFolder.FullName)
    For Each subF As IO.DirectoryInfo In BaseFolder.GetDirectories()
        AddContents(subF)
    Next
End Sub