-1

我的目录结构如下。

  • 目录 1 > subdir1_1 >((subdir1_1_1 >subdir1_1_1_1),subdir1_1_2)
  • 目录2

    两个主目录和 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 。为什么 ??

哪里有问题??为什么我不能得到空文件夹? 在此处输入图像描述

4

1 回答 1

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
于 2015-12-26T14:35:23.013 回答