删除目录下所有文件,包括子目录 Private Const FO_COPY = &H1 Private Const FO_MOVE = &H2 Private Const FO_DELETE = &H3 Private Const FO_RENAME = &H3 Private Const FOF_NOCONFIRMATION = &H10 Private Const FOF_SILENT = &H4 Private Const FOF_NOERRORUI = &H400 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 fAnyOperationsAborted As Long hNameMappings As Long lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS End TypePublic Function KillPath(ByVal sPath As String) As Boolean Dim udtPath As SHFILEOPSTRUCT udtPath.hwnd = 0 udtPath.wFunc = FO_DELETE udtPath.pFrom = sPath udtPath.pTo = "" udtPath.fFlags = FOF_NOCONFIRMATION Or FOF_SILENT Or FOF_NOERRORUI KillPath = Not CBool(SHFileOperation(udtPath)) End Function
Private Const FO_COPY = &H1
Private Const FO_MOVE = &H2
Private Const FO_DELETE = &H3
Private Const FO_RENAME = &H3
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_SILENT = &H4
Private Const FOF_NOERRORUI = &H400
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
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End TypePublic Function KillPath(ByVal sPath As String) As Boolean
Dim udtPath As SHFILEOPSTRUCT
udtPath.hwnd = 0
udtPath.wFunc = FO_DELETE
udtPath.pFrom = sPath
udtPath.pTo = ""
udtPath.fFlags = FOF_NOCONFIRMATION Or FOF_SILENT Or FOF_NOERRORUI
KillPath = Not CBool(SHFileOperation(udtPath))
End Function