borderAndreaVB free resources for Visual Basic developersborder

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincani
:: How to send files to the Recycle Bin

Author  

Andrea Tincani

Language  

VB5, VB6

Operating Systems  

Windows 95, 98 and NT
API Declarations

' Structures
Private Type SHFILEOPSTRUCT
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Long
    hNameMappings As Long
    lpszProgressTitle As Long
End Type

' API
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

' Contants
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10
' Responds with "yes to all" for any dialog box that is displayed.
Private Const FOF_SILENT = &H4                   
' Does not display a progress dialog box.

Module

'Move the file to the recycle bin
Public Sub SendFileToRecycleBin(FileName As String, Optional Confirm As Boolean = True, Optional Silent As Boolean = False)
    Dim FileOp As SHFILEOPSTRUCT

   
'fills the file operation structure
    With FileOp
        .wFunc = FO_DELETE
        .pFrom = FileName
        .fFlags = FOF_ALLOWUNDO
        If Not Confirm Then .fFlags = .fFlags + FOF_NOCONFIRMATION
        If Silent Then .fFlags = .fFlags + FOF_SILENT
    End With
    SHFileOperation FileOp
End Sub

Usage

' Usage:
Private Sub Command1_Click()
    SendFileToRecycleBin "C:\filename.ext", False
End Sub

:: Navigation

Home

Files and Disks Tips

Previous Tip

Next Tip

:: Search this site
Google
:: Related Topics
icon 07-08-2008 disabling right click operations on a specified file by vikramthevictor
icon 17-10-2004 Re: ssfPERSONAL in WinXP by VBer
:: Sponsored Links



Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder