VB 检测文件夹是否为空

来源:百度知道 编辑:UC知道 时间:2024/05/16 16:23:07
RT
一楼的,查了没有才问的。而且你的还不行哦。
二楼的,我只是改了路径而已啊App.Path & "\part"就不行了

Private Sub Command1_Click()
'先引用Microsoft Scripting Runtime
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.GetFolder("z:\temp").Files.Count > 0 Then
MsgBox "不为空" & fso.GetFolder("z:\temp").Files.Count
Else
MsgBox "空"
End If

End Sub

不能判断子目录

==========可以啊 改相对路径也没问题 除非你没有那个文件夹

Private Sub Command1_Click()
'先引用Microsoft Scripting Runtime
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.GetFolder(App.Path & "\temp").Files.Count > 0 Then
MsgBox "不为空" & fso.GetFolder(App.Path & "\temp").Files.Count
Else
MsgBox "空"
End If

End Sub

有一个很简单的方法,用 RmDir 文件夹,直接删除文件夹。

如果删除出错,那就表示文件夹不是空的。