John J. said:
I noticed that rmdir doesnt'work if there are subfolders and files in the
folder. Is there some function available that first clears all contents of
the folder and then deletes the folder itself?
Thank you,
John
Hi John
Try this:
===================================================================
Private Sub RemoveFoldersAndFiles(sPath As String)
If Right(sPath, 1) = "\" Then sPath = Left$(sPath, Len(sPath) - 1)
Dim fso As New Scripting.FileSystemObject
fso.DeleteFolder sPath
'You can also pass a second argument and set it to True if you want to force
the deletion of read-only files:
'fso.DeleteFolder sPath, True
End Sub
=======================================================================
Private Sub Command1_Click()
RemoveFoldersAndFiles "c:\theFolder"
End Sub
========================================================================
You need to add a reference to the Microsoft Scripting Runtime.
Good luck
Harold