This example shows you how to send a file to the recycle bin, instead of permanently deleting it.
First, add a command button called cmdDelete, and a textbox called txtFileName. Add the code below, run your project, enter a file to delete, and click the button!
Option Explicit
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 ' only used if
FOF_SIMPLEPROGRESS
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 cmdDelete_Click()
Dim op As SHFILEOPSTRUCT
With op
.wFunc = FO_DELETE
.pFrom = txtFileName.Text
.fFlags = FOF_ALLOWUNDO
End With
SHFileOperation op
End Sub
Comments