获取最后一个子目录路径列表 - vb.net

时间:2015-05-27 06:18:27

标签: .net vb.net

我正在尝试获取最后一个子目录的路径列表。

让我们假设我的C盘上有一个名为" Test"正如你在图片上看到的那样 enter image description here

我需要获取所有最后一个子目录的列表,其中标有红色,结果应如下所示: C:\测试\ 1 \一个 C:\测试\ 1 \ b C:\测试\ 1 \ C C:\测试\ 1 \ d C:\测试\ 2 \一个 。 。 。 。 C:\测试\ 5 \ d

就是这样。

感谢和最好的问候

1 个答案:

答案 0 :(得分:0)

在System.Io的帮助下,您可以执行此操作。请考虑以下代码:

    Dim di As DirectoryInfo = New DirectoryInfo("D:\folder")
    Dim directories() As DirectoryInfo = di.GetDirectories("*", SearchOption.AllDirectories)
    Dim ListOfEmptyDirectory As New List(Of String)
    For Each dir As DirectoryInfo In directories
        If dir.GetDirectories("*", SearchOption.AllDirectories).Count = 0 Then
            ListOfEmptyDirectory.Add(dir.FullName)'Gives the List of Last sub directories in the given folder;
        End If
    Next

如果您希望Last of子目录列为空,则按如下所示更改条件

   If dir.GetDirectories("*", SearchOption.AllDirectories).Count = 0 And dir.GetFiles().Count() = 0 Then
      ListOfEmptyDirectory.Add(dir.FullName)
   End If
相关问题