Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDelete a directory and everything it contains using the File System Object
KeywordsFile System Object, file, directory, dir
CategoriesAlgorithms, Files and Directories
 
Use the File System Object's DeleteFolder method. Note that this permanently removes the directory and everything it contains, it does not move it to the wastebasket.
 
' If the user presses the Delete key, delete the
' currently displayed file.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As _
    Integer)
Dim dir_name As String
Dim fso As FileSystemObject

    If KeyCode = vbKeyDelete Then
        ' Make the user confirm.
        dir_name = DirList.List(DirList.ListIndex)
        If MsgBox("Permanently delete directory " & _
            dir_name & " and everything it contains?", _
            vbQuestion Or vbYesNo, _
            "Delete Directory?") = vbNo _
                Then Exit Sub

        ' Delete the directory.
        Set fso = New FileSystemObject
        fso.DeleteFolder dir_name, True

        DirList.Refresh
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated