復制代碼- Function DelFolder(Str As String) As Boolean
- Rem RMdir的升級版本,根據目錄地址刪除最后文件夾及里面的文件
- Rem 使用方法Call RMDirs("D:\test\test2\test3")
- Rem if RMDirs("D:\test\test2\test3")=True then doSomething else doOtherSomething
- Err.Clear
- On Error GoTo ele
- Dim fs, f
- If Len(Str) = 0 Then Exit Function
- Set fs = CreateObject("Scripting.FileSystemObject")
- Set f = fs.GetFolder(Str)
- f.Delete
- DelFolder = True '刪除多級目錄成功
- Set fs = Nothing
- Set f = Nothing
- Exit Function
- ele:
- DelFolder = False '刪除多級目錄失敗
- Set fs = Nothing
- Set f = Nothing
- 'MsgBox Err.number & Err.Description
- End Function
|