Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 14,267 times

Related Categories

Send to Recycle Bin

This example shows you how to send a file to the recycle bin, instead of permanently deleting it.

First, add a command button called cmdDelete, and a textbox called txtFileName. Add the code below, run your project, enter a file to delete, and click the button!

Option Explicit

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 '  only used if FOF_SIMPLEPROGRESS
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 Sub cmdDelete_Click()
Dim op As SHFILEOPSTRUCT

    With op
        .wFunc = FO_DELETE
        .pFrom = txtFileName.Text
        .fFlags = FOF_ALLOWUNDO
    End With
    SHFileOperation op
End Sub

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • can't i by pass the Confirm File Delete dialog box

    Posted by RUK007 on 09 Jul 2005

    i want to bypass the 'Confirm File Delete' dialog box when i delete an exe file..
    i dont want the user to see that dialog box when this piece of code is executed..
    can this be done
    btw this is an e...