Summary:
Procedure sends a file to the Recycle Bin and updates the Recycle Bin icon.
VB Code:
  1. Option Explicit
  2.  
  3. 'declare api procedures
  4.     Private Declare Function SHFileOperation Lib "shell32.dll" _
  5.         Alias "SHFileOperationA" _
  6.         (lpFileOp As SHFILEOPSTRUCT) As Long
  7.        
  8.     Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Long
  9.  
  10. 'declare constants
  11.     Private Const FO_DELETE = &H3
  12.     Private Const FOF_ALLOWUNDO = &H40
  13.    
  14. 'declare udt's
  15.     Private Type SHFILEOPSTRUCT
  16.         hWnd As Long
  17.         wFunc As Long
  18.         pFrom As String
  19.         pTo As String
  20.         fFlags As Integer
  21.         fAborted As Boolean
  22.         hNameMaps As Long
  23.         sProgress As String
  24.     End Type
  25.  
  26. Public Sub RecycleFile(FileSpec As String)
  27.     On Error Resume Next
  28.  
  29.     'initialize variable
  30.     Dim SHFileOp As SHFILEOPSTRUCT
  31.    
  32.     'configure file operation
  33.     With SHFileOp
  34.         '...specify `Delete` operation
  35.         .wFunc = FO_DELETE
  36.        
  37.         '...specify the file
  38.         .pFrom = FileSpec
  39.        
  40.         '...specify send to recycle bin
  41.         .fFlags = FOF_ALLOWUNDO
  42.     End With
  43.    
  44.     'perform file operation
  45.     SHFileOperation SHFileOp
  46.    
  47.     'update recycle bin icon
  48.     SHUpdateRecycleBinIcon
  49. End Sub

Usage Example:
VB Code:
  1. RecycleFile "c:\recycleme.txt"