|
|
Удаление папки со всем содержимым (FSO + Shell)
Public Function DeleteFolderAndContent(ByVal sFolder$) As Boolean
Dim objFSO As Object
On Error GoTo DeleteFolderAndContent_Err
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Right(sFolder, 1) = "\" Then
sFolder = Mid(sFolder, 1, Len(sFolder) - 1)
End If
objFSO.DeleteFolder sFolder, True
DeleteFolderAndContent = True
DeleteFolderAndContent_End:
On Error Resume Next
Set objFSO = Nothing
Err.Clear
Exit Function
DeleteFolderAndContent_Err:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Function DeleteFolderAndContent.", _
vbCritical, "Произошла ошибка!"
Err.Clear
Resume DeleteFolderAndContent_End
End Function
Ещё вариант с Shell - Работает мгновенно (даже слишком) и ошибок не возвращает :
Public Sub DeleteFolderAndContent(ByVal sFolder$)
sFolder = sFolder & IIf(Right(sFolder, 1) = "\", "", "\")
Shell "cmd /c rd /S/Q """ & sFolder & """"
End Sub
|
|