Prøv denne. Hust at tilføj Reference til Microsoft Scripting Runtime.
Option Explicit Dim objFSO As Scripting.FileSystemObject
Private Sub Command1_Click() Set objFSO = New Scripting.FileSystemObject objFSO.DeleteFolder (\"C:\\Windows\\temp\\test\"), True Set objFSO = Nothing End Sub
Følgende sletter et directory og dets subdirectories
Private Declare Function SHFileOperation Lib \"shell32.dll\" _ Alias \"SHFileOperationA\" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Type SHFILEOPSTRUCT hWnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAborted As Boolean hNameMaps As Long sProgress As String End Type
Public Sub SletFiler(sPath As String) Dim SHFileOp As SHFILEOPSTRUCT sPath = sPath & Chr$(0) & Chr$(0)
\'Initialisering af options With SHFileOp .wFunc = FO_DELETE .pFrom = sPath .fFlags = FOF_FILESONLY Or _ FOF_SILENT Or _ FOF_NOCONFIRMATION Or _ FOF_ALLOWUNDO End With
\'slet biblioteker og underbiblioteker Call SHFileOperation(SHFileOp)
end sub
private sub command1_Click() Sletfiler(\"c:\\TEST\\\") end sub
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.