Thema
Unterverzeichnisse mit Inhalt löschen
Gruppe
Dateien
Problem
Wie kann ich über VBA-Code einen bestimmten Vereichnisbaum einschließlich der Dateien löschen?
StandardModule: basMain Von Jim Rech Private Const FO_DELETE = &H3& Private Const FOF_ALLOWUNDO = &H40& Private Const FOF_NOCONFIRMATION = &H10& Private Type SHFILEOPSTRUCT hwnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAnyOperationsAborted As Long hNameMappings As Long lpszProgressTitle As String End Type Private Declare Function SHFileOperation Lib "Shell32.dll" Alias _ "SHFileOperationA" (lpFileOp As Any) As Long Sub ShellDelete(SrcFile As String) Dim FileOp As SHFILEOPSTRUCT With FileOp .hwnd = 0 .wFunc = FO_DELETE .pFrom = SrcFile .fFlags = FOF_NOCONFIRMATION + FOF_ALLOWUNDO .lpszProgressTitle = "" End With SHFileOperation FileOp End Sub Sub DeleteFolder() Dim sFolder As String sFolder = InputBox( _ prompt:="Zu löschender Ordner:", _ Default:="c:\MyFolder") If sFolder = "" Then Exit Sub If MsgBox( _ prompt:="Sind Sie sicher?", _ Buttons:=vbQuestion + vbYesNo) = vbYes Then ShellDelete "c:\MyDir" End If End Sub