?
Solved

Move to Recycle Bin Silently

Posted on 2003-03-19
6
Medium Priority
?
322 Views
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



ldavies
0
Comment
Question by:ldavies83
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 8166533
Hi spg01,

Have you used

Public Const FOF_SILENT = &H4                      

Rather than FOF_NOCONFIRMATION which is the inverse of FOF_ALLOWUNDO.

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0
 

Author Comment

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

    Type SHFILEOPSTRUCT
       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
    Else
        Temp2String = InPathTemp
    End If
   
        'Get the actual FileName
        FileName = Mid(InPathTemp, InStrRev(InPathTemp, "\") + 1)
   
    If RecycleBin = False Then
        'Delete Permanantly
        fso.DeleteFile Temp2String, True
    Else
        '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
    Else
        DeleteFile = "0 - Success"
    End If
    Exit Function
   
prbDeleteFile:
    MsgBox Err.Number & " - " & Err.Description
    DeleteFile = Err.Number & " - " & Err.Description
    Exit Function
End Function
0
 
LVL 43

Expert Comment

by:TimCottee
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.
0
Technology Partners: 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

by:ldavies83
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
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 total points
ID: 8166772
ldavies:

I have just tried your code with:

.fFlags = .fFlags OR FOF_SILENT OR FOF_NOCONFIRMATION

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

0
 

Author Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 Month8 days, 8 hours left to enroll

764 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