Sending File(s) to the Recycle Bin

ZeroEffect

Well-known member
Joined
Oct 24, 2004
Messages
180
Location
Detroit, MI
Um? How can I do this. :confused:

I have found all these great things in .Net that has made moving, deleting, copying files easier. All the special folders are easy to find but why is it hard to move or send a file to the recycle bin with or without the conferimation diolog.

Any thoughts

Thanks

ZeroEffect
 
Update

Well I found this but it is just prompting for the delete.

Code:
Imports System.IO


    Private Structure SHFILEOPSTRUCT
        Dim hwnd As Integer
        Dim wFunc As Integer
        Dim pFrom As String
        Dim pTo As String
        Dim fFlags As Short
        Dim fAnyOperationsAborted As Boolean
        Dim hNameMappings As Integer
        Dim lpszProgressTitle As String
    End Structure

    Private Const FO_DELETE As Short = &H3S
    Private Const FOF_ALLOWUNDO As Short = &H40S
    Private Const FOF_NOCONFIRMATION As Short = &H10S

    Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer

   Public Function Recycle(ByRef sPath As String) As Integer
        Dim FileOp As SHFILEOPSTRUCT
        If Not File.Exists(sPath) Then
            MsgBox("Could not find " & sPath & "." & vbCrLf _
            & "Please verify the path.")
            Recycle = -1
            Exit Function
        End If
        With FileOp
            .wFunc = FO_DELETE
            .fFlags = FOF_ALLOWUNDO Or FOF_NOCONFIRMATION
            .pFrom = sPath & vbNullChar
            .pTo = vbNullChar
        End With
        Try
            SHFileOperation(FileOp)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Recycle = 0
    End Function

Any Thoughts

ZeroEffect
 
I dont know if there is a way to bypass the "Are you Sure?" dialog when deleting a file. You can turn the dialog off from the properties of the recycling bin. I dont know how to do it programmatically. Maybe a registry key?
 
After doing a bit more research I found this. I hope this helps you.
Code:
Turns off the recycle bin delete confirmation for all drives
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]
"ShellState"=hex:24,00,00,00,37,a8,01,00,00,00,00,00,00,00,00,00,00,00,00,00,\ 01,00,00,00,0d,00,00,00,00,00,00,00,02,00,00,00
 
Generally, I would say that if the file you are deleting isnt a file that the user needs to know about then you should not worry about sending it to the recycle bin; just delete it. If it is a file that needs to be sent to the recycle bin in case the user will want to recover it, a message to the user confirming the delete might be appropriate so that the user knows what is going on.

I hope you arent going do distribute a program that disables the "Are you sure" prompt for deleting the files. Even if it is only temporary, in the event of an error in your application this can cause very undesirable behavior on the end users machine. I wouldnt want such software running on my PC, and depending on how it is programmed, the user might accidentally delete other files without even realizing it any time your program is running.

By the look of things, that registry setting may alter other settings as well. Unless you know for a fact that this is not the case, I recommend doing more research on that registry key.
 
The Goal

marble_eater said:
Generally, I would say that if the file you are deleting isnt a file that the user needs to know about then you should not worry about sending it to the recycle bin; just delete it. If it is a file that needs to be sent to the recycle bin in case the user will want to recover it, a message to the user confirming the delete might be appropriate so that the user knows what is going on.

I hope you arent going do distribute a program that disables the "Are you sure" prompt for deleting the files. Even if it is only temporary, in the event of an error in your application this can cause very undesirable behavior on the end users machine. I wouldnt want such software running on my PC, and depending on how it is programmed, the user might accidentally delete other files without even realizing it any time your program is running.

By the look of things, that registry setting may alter other settings as well. Unless you know for a fact that this is not the case, I recommend doing more research on that registry key.

First off thanks for the replys! :)

Basicly I am writing a program to automate the archiving of files. I have a folder I have to mannually archive everyweek. Leave the newest two weeks move the third to an archive folder. In the archive folder delete the oldest weeks worth of files. I wanted to have the option of just sending the files to the recycle bin built into the application.

Now with the code in my earlier post I can supress the confirmation prompt (app only) but it deletes the files and the prompt that is displayed when it is not supressed is the one when you hold down the "Shift" key and hit delete while a file is selected. The option of sending the file to the recycle bin doesnt come up.

I have the whole thing done other than the option for the recycle bin.

Any other thoughts, I do think this wilol help more people that just me.

Thanks for all the input from everyone.

ZeroEffect
 
jo0ls said:
http://www.codeproject.com/shell/recyclebin.asp

c++ , but good explanations of what hes doing.

I think I might have to read this a few times, I dont know C++. So its losing me a little. I also dont have C++ so the source files are no good to me. I do think the artical is good I just need to get some more knowledge before Im able to under stand it.

Does any one know of a VB.Net example?

Thanks for the help

ZeroEffect
 
Just a thought: If you want the files to be recoverable, why not simply remove them to your [applications] own backup folder instead of cluttering the recycle bin?
 
Thanks

marble_eater said:
Just a thought: If you want the files to be recoverable, why not simply remove them to your [applications] own backup folder instead of cluttering the recycle bin?

I think that might be my best option for right now. Refering to the post to above this one. Those flags with the code above still bypassed the recycle bin. :(

Thanks for all you help.

ZeroEffect
 
Back
Top