Results 1 to 3 of 3

Thread: VB6 - Moving Files to the Recycle Bin

Threaded View

  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+++

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