4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by SI THU
0

One way is to add the Scripting Type Library to your project and use the File System Object. From the Project Menu in your IDE, choose the References Menu. Look for the Microsoft scripting runtime libray and add it to your project.

Private Sub DeleteFolder (ByVal FolderName as String)
Dim fso as New FileSystemObject

fso.DeleteFolder (FolderName)
' Zero out memory for file system object
set fso = Nothing
End Sub

Edited by hkdani: n/a

0

The RmDir command can delete a directory only if it doesn't contain files or sub-directories. If the directory you want to delete does contain other files or, worse, subdirectories it seems that you are forced to use a recursive routine that does the job.

A simpler solution is offered by the DeleteFolder method of the FileSystemObject object, exposed by the Microsoft Scripting Runtime library:

' NOTE: this code requires that you add a reference to the
'       Microsoft Scripting Runtime type library

' delete the C:\TEMP directory and all its sub-directories
Dim fso As New Scripting.FileSystemObject
fso.DeleteFolder "c:\temp"

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 "c:\temp", True
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.