This code will delete items to the recycle bin.
Option Explicit
Private Sub Command1_Click()
Dim result As Long
Dim fileop As SHFILEOPSTRUCT
With fileop
.hwnd = Me.hwnd
.wFunc = FO_COPY
'The files to copy separated by Nulls and terminated by 2
'null. The files VB.HLP and VB.CNT are installed by a complete
'installation of Microsoft Visual Basic. If you do not have
'these files, you can alter this sample to point to existing
'files.
.pFrom = "C:\PROGRAM FILES\DevStudio\VB\Readme.HLP" & _
vbNullChar & _
"C:\PROGRAM FILES\DevStudio\VB\Readme.CNT" & _
vbNullChar & vbNullChar
'or to copy all files use this line
'.pFrom = "C:\*.*" & vbNullChar & vbNullChar
'The directory or filename(s) to copy into terminated in 2
'nulls.
.pTo = "C:\testfolder\" & vbNullChar & vbNullChar
.fFlags = FOF_SIMPLEPROGRESS Or FOF_FILESONLY
End With
result = SHFileOperation(fileop)
If result <> 0 Then 'Operation failed
MsgBox result, , "Copy Operation Failed"
Else
If fileop.fAnyOperationsAborted <> 0 Then
MsgBox fileop.fAnyOperationsAborted, , "Operation Aborted"
End If
End If
End Sub
Private Sub Command2_Click()
Dim DelFileOp As SHFILEOPSTRUCT
Dim result As Long
With DelFileOp
.hwnd = Me.hwnd
.wFunc = FO_DELETE
'Delete the files you just moved to C:\TestFolder.
'The files VB.HLP and VB.CNT are installed by a complete
'installation of Microsoft Visual Basic. If you do not have
'these files, you can alter this sample to point to existing
'files.
.pFrom = "C:\testfolder\Readme.hlp" & vbNullChar & _
"c:\testfolder\Readme.cnt" & vbNullChar & vbNullChar
'Allow undo--in other words, place the files into the Recycle
'Bin
.fFlags = FOF_ALLOWUNDO
End With
result = SHFileOperation(DelFileOp)
If result <> 0 Then 'Operation failed
MsgBox result, , "Delete Operation Failed"
Else
If DelFileOp.fAnyOperationsAborted <> 0 Then
MsgBox DelFileOp.fAnyOperationsAborted, , "Operation Aborted"
End If
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "Copy Test"
Command2.Caption = "Recycle Test"
End Sub
*********************************Add this code to a module*********************************
Option Explicit
Public Const FO_MOVE As Long = &H1
Public Const FO_COPY As Long = &H2
Public Const FO_DELETE As Long = &H3
Public Const FO_RENAME As Long = &H4
Public Const FOF_MULTIDESTFILES As Long = &H1
Public Const FOF_CONFIRMMOUSE As Long = &H2
Public Const FOF_SILENT As Long = &H4
Public Const FOF_RENAMEONCOLLISION As Long = &H8
Public Const FOF_NOCONFIRMATION As Long = &H10
Public Const FOF_WANTMAPPINGHANDLE As Long = &H20
Public Const FOF_CREATEPROGRESSDLG As Long = &H0
Public Const FOF_ALLOWUNDO As Long = &H40
Public Const FOF_FILESONLY As Long = &H80
Public Const FOF_SIMPLEPROGRESS As Long = &H100
Public Const FOF_NOCONFIRMMKDIR As Long = &H200
Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Long
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String
End Type
Declare Function SHFileOperation Lib "Shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long