[vb]代码库
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef 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 Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type
Public Const FO_Delete = &H3
Public Const FOF_ALLOWUNDO = &H40
Public Const HWND_DESKTOP = 0
Public Const NOCONFIRMATION = &H10 '不提示
'函数定义
Function DeleteFiles(Path As String) '定义删除文件函数
Dim Shop As SHFILEOPSTRUCT
With Shop
.hwnd = HWND_DESKTOP
.pTo = ""
.wFunc = FO_Delete
.pFrom = Path + Chr(0)
.fFlags = FOF_ALLOWUNDO + NOCONFIRMATION
End With
SHFileOperation Shop
End Function
'以上是定义内容,之后可以在任意过程中调用,示例如下:
Public Sub aaaa() '调用
DeleteFiles "C:\New Text Document.txt"
End Sub