VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Send a file to the Recycle Bin rather than deleting it comletely

by Justin Coleman - from VB Tech Tips by VBPJ (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sat 25th September 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Send a file to the Recycle Bin rather than deleting it comletely

API Declarations


hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
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 Const FOF_CREATEPROGRESSDLG As Long = &H0
Public Enum RemoveAction
rfRecycle = 1
rfDelete = 2
End Enum

Rate Send a file to the Recycle Bin rather than deleting it comletely



    Dim FileOperation As SHFILEOPSTRUCT
    Dim lReturn As Long
    On Error GoTo RemoveFile_Err
    With FileOperation
        .wFunc = FO_DELETE
        .pFrom = filename
        If action = rfRecycle Then
            .fFlags = FOF_ALLOWUNDO + FOF_CREATEPROGRESSDLG
        Else
            .fFlags = FO_DELETE + FOF_CREATEPROGRESSDLG
        End If
    End With
    lReturn = SHFileOperation(FileOperation)
    If lReturn <> 0 Then
        RemoveFile = False
    Else
        RemoveFile = True
    End If
    Exit Function
RemoveFile_Err:
    RemoveFile = False
End Function

Download this snippet    Add to My Saved Code

Send a file to the Recycle Bin rather than deleting it comletely Comments

No comments have been posted about Send a file to the Recycle Bin rather than deleting it comletely. Why not be the first to post a comment about Send a file to the Recycle Bin rather than deleting it comletely.

Post your comment

Subject:
Message:
0/1000 characters