|
|
Title | Delete a directory and everything it contains using the File System Object |
Keywords | File System Object, file, directory, dir |
Categories | Algorithms, 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
|
|
|
|
|
|