vb.net,一文件夹下存在若干子文件夹,如何判断哪些子文件夹为空(子文
发布网友
发布时间:2022-04-22 19:56
我来回答
共1个回答
热心网友
时间:2023-11-17 22:10
'通过过System.IO.DirectoryInfo对象可以查阅目录信息,下面是遍历一个文件夹下所有层次的子文件夹,如果只检查下一层目录就更简单了。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim folder = New System.IO.DirectoryInfo("D:\Documents")
Dim items = getemptyfolder(folder)
For Each item In items
Console.WriteLine(item.FullName)
Next
End Sub
Function getemptyfolder(ByVal folder As System.IO.DirectoryInfo) As System.IO.DirectoryInfo()
Dim items As New List(Of System.IO.DirectoryInfo)
If folder.EnumerateFiles().Count = 0 Then
items.Add(folder)
End If
Dim subfolders = folder.EnumerateDirectories()
For Each subfolder In subfolders
items.AddRange(getemptyfolder(subfolder)) '查询树形目录结构类型数据用递归法实现
Next
Return items.ToArray()
End Function
'还是学c#语言吧,我发觉同样一个数组,c#功能多的多,vb.net没几条方法可用。