I want to delete all files and folders in the My Documents folder. I tried FSO create object command, it deletes files only but failed to delete folder. Is there any other way to delete files and folders in the My Document folder without using FSO create object function?

This is my code.

Sub GetSpecialFolderPath()

Dim objSFolders As Object

Dim MyPath As String

Set objSFolders = CreateObject("WScript.Shell").SpecialFolders

MyPath = objSFolders("mydocuments")

Dim FSO As Object

Set FSO = CreateObject("scripting.filesystemobject")

MyPath = .Range("B2").Value

If Right(MyPath, 1) = "\" Then

MyPath = Left(MyPath, Len(MyPath) - 1)

End If

If FSO.FolderExists(MyPath) = False Then
MsgBox MyPath & " doesn't exist"
Exit Sub
End If

On Error Resume Next
FSO.deletefolder MyPath & "\*.*", True
'Delete files
FSO.deletefile MyPath & "\*.*", True
'Delete subfolders
FSO.deletefolder MyPath & "\*.*", True
On Error GoTo 0
End Sub