Results 1 to 3 of 3

Thread: VB6 - Moving Files to the Recycle Bin

  1. #1

    Thread Starter
    Addicted Member ripple214's Avatar
    Join Date
    Nov 2002
    Location
    In Front of My Computer
    Posts
    141

    VB6 - Moving Files to the Recycle Bin

    When a file is deleted in windows, it is not automatically erased. Instead, it is put into the recycle bin. Thus, an unwanted deletion can easily be undone. You can do this in your programs with these codes;
    VB Code:
    1. ' Copy this code into a module
    2. ' You can add a module by right clicking in the project
    3. ' explorer of vb
    4.  
    5. Public Type SHFILEOPSTRUCT
    6.  
    7. hwnd As LongwFunc As
    8. LongpFrom As StringpTo As Stringf
    9. Flags As Integer
    10. fAnyOperationsAborted As Long
    11. hNameMappings As Long
    12. lpszProgressTitle As Long
    13.  
    14. End Type
    15.  
    16. Public Declare Function SHFileOperation Lib _"shell32.dll" _ Alias "SHFileOperationA" (lpFileOp _As SHFILEOPSTRUCT) As Long
    17.  
    18. Public Const FO_DELETE = &H3
    19. Public Const FOF_ALLOWUNDO = &H40
    20.  
    21. Public Function Move2RecycleBin(strfile as String)
    22. 'strfile is the full path of the file you want to put in the recycle bin
    23. Dim SHop As SHFILEOPSTRUCT
    24. With SHop
    25.  
    26. .wFunc = FO_DELETE
    27. .pFrom = strFile
    28. .fFlags = FOF_ALLOWUNDO
    29.  
    30. End With
    31. SHFileOperation SHop
    32. End Function
    33.  
    34. 'Sample Usage
    35. Private Sub Form1_Activate()
    36. Move2RecycleBin("C:\PutMe.txt")
    37. End Sub
    38.  
    39. 'Code By : Rigie O. Acebedo
    Last edited by ripple214; Mar 18th, 2003 at 12:04 PM.
    [vbcode]
    If SymptomsPersist Then Goto VBForum
    [/vbcode]
    This is our world now...the world of the electron and the switch, the beauty of the baud.We make use of a service already existing without paying for what could be dirt cheep if it wasn't run by profiteering gluttons, and you call us criminals. We explore...and you call us criminals. We exist without skin color, without nationality, without religious bias...and you call us criminals. You build atomic bombs, wage wars, murder, cheat, and lie to us and try to make us believe it is for our own good, yet we're the criminals. Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for. I am a hacker and this is my manifesto.You may stop this individual, but you can't stop us all...after all, we're all alike."

    +++The Mentor+++

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB6 - Moving Files to the Recycle Bin

    You should check for the possibility of the user Canceling the dialog. You do that by looking at If FileOperation.fAnyOperationsAborted which will be True in that case.

  3. #3
    Member
    Join Date
    Mar 2024
    Posts
    45

    Re: VB6 - Moving Files to the Recycle Bin

    For an update as of August, 2024 under Windows 10 the function provided still works perfectly.

    It works with reasonable speed but not as quickly as the simple "NAME" command that I previously used when saving files that might be needed later or "accidentally" erased.

    My present program is working with tens of thousands of files of wildly varying size and multiple format so speed is actually becoming significant factor and I'm employing a virtual disc for the first time since I used them (in "extended" memory) to store simple text screen images enabling effectively instant screen changes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width