is there a way in visual basic to delete a folder that contains files our other folders, like a deltree in dos.
I've tried "rmdir (path)" but there is a error if the folder contains file.
thanxs
Printable View
is there a way in visual basic to delete a folder that contains files our other folders, like a deltree in dos.
I've tried "rmdir (path)" but there is a error if the folder contains file.
thanxs
Just use Deltree.
Becareful, this could delete important files. It is very dangerous! :rolleyes:Code:Shell "DELTREE /Y (path)", vbHide
This uses the Microsoft Scripting Control to create the object, but it's a pretty decent solution (I like the FileSystemObject :)Code:'You Need Microsoft Scripting Control for this.
'Not verified
Dim fOps As Object
Private Function DelTree(dirPath As String, Optional delReadOnly As Boolean) As Boolean
Set fOps = CreateObject("Scripting.FileSystemObject")
If fOps.FolderExists(dirPath) = True Then
If delReadOnly <> True Then
fOps.DeleteFolder dirPath
Else
fOps.DeleteFolder dirPath, delReadOnly
End If
DelTree = True
Else
DelTree = False
End If
End Function
The Function is called thusly: DidDelete = delTree(PATH,[True/False])
If True is set, it will delete read only folders, if false is set, it will not. Path is the directory you wish to delete. The function returns either a true or a false indicating it's level of success.