VB Code:
  1. Private Type SHFILEOPSTRUCT
  2.     hWnd As Long
  3.     wFunc As Long
  4.     pFrom As String
  5.     pTo As String
  6.     fFlags As Integer
  7.     fAnyOperationsAborted As Boolean
  8.     hNameMappings As Long
  9.     lpszProgressTitle As String
  10. End Type
  11.  
  12. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
  13.  
  14. Private Const FO_DELETE = &H3
  15. Private Const FOF_ALLOWUNDO = &H40
  16. Private Const FOF_CREATEPROGRESSDLG As Long = &H0
  17.  
  18. Private Enum WhatDoIDoWithIt
  19.     SendToRecycle = 1
  20.     WhackIt = 2
  21. End Enum
  22.  
  23. Private Function TrashFile(FileName As String, How As WhatDoIDoWithIt) As Boolean
  24.     Dim FileOperation As SHFILEOPSTRUCT
  25.     Dim RetCode As Long
  26.     On Error GoTo WhackItError
  27.     With FileOperation
  28.         .wFunc = FO_DELETE
  29.         .pFrom = FileName
  30.         If How = SendToRecycle Then
  31.             .fFlags = FOF_ALLOWUNDO + FOF_CREATEPROGRESSDLG
  32.         Else
  33.             .fFlags = FO_DELETE + FOF_CREATEPROGRESSDLG
  34.         End If
  35.     End With
  36.     RetCode = SHFileOperation(FileOperation)
  37.     If RetCode <> 0 Then
  38.         TrashFile = False
  39.     Else
  40.         TrashFile = True
  41.     End If
  42.     Exit Function
  43. WhackItError:
  44.     TrashFile = False
  45.     MsgBox Err & " " & Error
  46. End Function
  47.  
  48. Private Sub Command1_Click()
  49. 'to delete it entirely, as with Kill
  50. TrashFile "c:\baby.txt", WhackIt
  51. 'or to send it to the recycle bin
  52. TrashFile "c:\baby.txt", SendToRecycle
  53. End Sub
The FOF_CREATEPROGRESSDLG is optional, but I like it. It pops up the message box asking if you want to send the file to the recycle bin, or if you are sure you want to delete it.