|
發表於 2006-7-23 16:28:11
|
顯示全部樓層
vb 判斷某資料夾是否為空資料夾
Function IsEmptyFolder(sFolder As String) As Boolean
On Error GoTo ErrLine
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(sFolder)
'傳回資料夾包含的所有檔案和子資料夾的大小 (以位元組為單位)。
If f.Size = 0 Then
IsFolderEmpty = True
Else
IsFolderEmpty = False
End If
Exit Function
ErrLine:
'資料夾不存在
Err = 0
IsEmptyFolder = True
End Function
範例:判斷 C:temp 資料夾是否為空
Sub test()
Dim sPath As String
sPath = "C:temp"
MsgBox sPath & "資料夾" & IIf(IsEmptyFolder(sPath), "為空", "不為空")
End Sub |
|