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

vb.net | How to get empty subdirectories in a specified path ? using vb.net

我的目录结构如下。

好的

现在我有了这个代码


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

这样试试

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