复制代码- 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
|