在公共模块之中:
Option Explicit
Public Const FO_MOVE = &H1
Public Const FO_COPY = &H2
Public Const FO_DELETE = &H3
Public Const FO_RENAME = &H4
Public Const FOF_NOCONFIRMATION = &H10
Public Const FOF_NOCONFIRMMKDIR = &H200
Public Const FOF_ALLOWUNDO = &H40
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
Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
窗体中:
Private Sub Command1_Click()
Dim SHFileOp As SHFILEOPSTRUCT
Dim Path As String, pFrom As String, i As Integer
pFrom ="c:\abc.exe"
SHFileOp.wFunc = FO_DELETE
SHFileOp.pFrom = pFrom
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION
SHFileOperation SHFileOp
End Sub