Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Move to Recycle Bin Silently

Posted on 2003-03-19
Medium Priority
Last Modified: 2012-05-04
We have an in house SMS type system we run and I'm trying to add a delete file module to it, It looks at a database for the file to look for, and also whether it should be sent to recycle bin or not. I have it all working bar the recycle bin part. All the examples on the internet do work, but they all ask for a confirmation however. I want the user to not even know the file has been moved to the recycle bin. I've tried the FOF_NOCONFIRMATION option, however, this seems to just bring up a delete confirmation for the file.
I'm giving this a high priority because I would like to see this fixed by the end of the day.
Thanks for this

Question by:ldavies83
  • 3
  • 3
LVL 43

Expert Comment

ID: 8166533
Hi spg01,

Have you used

Public Const FOF_SILENT = &H4                      

Rather than FOF_NOCONFIRMATION which is the inverse of FOF_ALLOWUNDO.


Brainbench MVP for Visual Basic

Experts-Exchange Advisory Board Member

Author Comment

ID: 8166579
Does exactly the same thing. This might help, here is my code:

       hwnd As Long
       wFunc As Long
       pFrom As String
       pTo As String
       fFlags As Long
       fAnyOperationsAborted As Long
       hNameMappings As Long
       lpszProgressTitle As String
    End Type
        Public Const FO_DELETE As Long = &H3
    Public Const FOF_MULTIDESTFILES As Long = &H1
    Public Const FOF_CONFIRMMOUSE As Long = &H2
    Public Const FOF_SILENT As Long = &H4
    Public Const FOF_RENAMEONCOLLISION As Long = &H8
    Public Const FOF_NOCONFIRMATION As Long = &H10
    Public Const FOF_WANTMAPPINGHANDLE As Long = &H20
    Public Const FOF_CREATEPROGRESSDLG As Long = &H0
    Public Const FOF_ALLOWUNDO As Long = &H40
    Public Const FOF_FILESONLY As Long = &H80
    Public Const FOF_SIMPLEPROGRESS As Long = &H100
    Public Const FOF_NOCONFIRMMKDIR As Long = &H200
    Declare Function SHFileOperation Lib "Shell32.dll" _
       Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Public Function DeleteFile(InPath As String, RecycleBin As Boolean) As String
Dim fso As FileSystemObject, InPathTemp As String, Temp1String As String, Temp2String As String, FileName As String, op As SHFILEOPSTRUCT, Result As Long

On Error GoTo prbDeleteFile
DeleteFile = "1 - Not Completed"
InPathTemp = InPath

    If InStr(InPathTemp, "%ProgramFiles%") > 0 Then
        Temp1String = Right(InPathTemp, Len(InPathTemp) - Len("%programfiles%"))
        Temp2String = ProgramFilesPath & Temp1String
    ElseIf InStr(InPathTemp, "%windir%") > 0 Then
        Temp1String = Right(InPathTemp, Len(InPathTemp) - Len("%windir%"))
        Temp2String = WinDir & Temp1String
        Temp2String = InPathTemp
    End If
        'Get the actual FileName
        FileName = Mid(InPathTemp, InStrRev(InPathTemp, "\") + 1)
    If RecycleBin = False Then
        'Delete Permanantly
        fso.DeleteFile Temp2String, True
        'Send to Recycle bin
        With op
            .hwnd = frmUpdater.hwnd
            .wFunc = FO_DELETE
            .pFrom = Temp2String
            .fFlags = FOF_ALLOWUNDO
            .fFlags = .fFlags And FOF_SILENT
        End With
        Result = SHFileOperation(op)
    End If
    If Result <> 0 Then
        MsgBox Err.LastDllError
        DeleteFile = "0 - Success"
    End If
    Exit Function
    MsgBox Err.Number & " - " & Err.Description
    DeleteFile = Err.Number & " - " & Err.Description
    Exit Function
End Function
LVL 43

Expert Comment

ID: 8166628
Try using .fFlags = .fFlags Or FOF_SILENT

It may seem strange but when setting things like this, to combine two values you often need to do a logical OR operation rather than an logical AND operation. It seems a bit funny but give it a go.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 8166709
Well, almost there, it's resorted back to asking confirmation on moving the file to the recycle bin. But you were right about the AND operation, it seemed to reset the value of fFlags to 0, instead of 68 with the OR clause. Still no luck with no confirmation however
LVL 43

Accepted Solution

TimCottee earned 2000 total points
ID: 8166772

I have just tried your code with:


And it seemed to work fine, perhaps I misinterpreted the relationship between allowundo and noconfirmation.


Author Comment

ID: 8166827
Bingo! Works a treat! Thankyou very much, you deserve the points for getting a solution sorted within 45 minutes!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question