Public Sub DeleteNullFolder(ByVal path As String)
'功能:删除空文件夹
'引用:Microsoft Scripting Runtime
Dim fso As New FileSystemObject
Dim fld As Folder
Dim subfld As Folder
If fso.FolderExists(path) = True Then
Set fld = fso.GetFolder(path)
If fld.SubFolders.Count = 0 And fld.Files.Count = 0 Then '无子文件夹和文件
fld.Delete
Else
If fld.SubFolders.Count > 0 Then '遍历子文件夹并递归,删除其中的空文件夹
For Each subfld In fld.SubFolders
Call DeleteNullFolder(subfld.path) '递归
Next
End If
If fld.SubFolders.Count = 0 And fld.Files.Count = 0 Then '经过删除子文件夹后,再判断是否为空文件夹
fld.Delete
End If
End If
End If
Set fso = Nothing
Set fld = Nothing
Set subfld = Nothing
End Sub