新建From1(窗体),新建Command1(按钮CommandButton),代码:
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 Long
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Sub Command1_Click()
Dim SHop As SHFILEOPSTRUCT
Dim strFile As String
strFile = App.Path & "\manongku.txt"
With SHop
.wFunc = FO_DELETE
.pFrom = strFile + Chr(0)
.fFlags = FOF_ALLOWUNDO
End With
SHFileOperation SHop
MsgBox strFile & "已经移动到回收站了。"
End Sub
回收站的文件是可以恢复的。可以参考《VB6 利用API清空回收站》。