P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Oct 10th, 2003 08:35 AM Post subject: Send File to the Recycle Bin |
|
|
| Code: | Option Explicit
'declare api procedures
Private Declare Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long
Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Long
'declare constants
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
'declare udt's
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Public Sub RecycleFile(FileSpec As String)
On Error Resume Next
'initialize variable
Dim SHFileOp As SHFILEOPSTRUCT
'configure file operation
With SHFileOp
'...specify `Delete` operation
.wFunc = FO_DELETE
'...specify the file
.pFrom = FileSpec
'...specify send to recycle bin
.fFlags = FOF_ALLOWUNDO
End With
'perform file operation
SHFileOperation SHFileOp
'update recycle bin icon
SHUpdateRecycleBinIcon
End Sub |
Usage :
| Code: | | RecycleFile "c:\recycleme.txt" |
_________________ No one is completely useless. They can at least be an example of what to avoid. |
|