Results 1 to 11 of 11

Thread: Sending Files to the Recycle Bin?!?!?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    Somewhere in Time
    Posts
    23

    Angry Sending Files to the Recycle Bin?!?!?

    Hey guys... i am stuck trying to creat a command or searching for one which will be able to send any file to the recycle bin.. from what i learned the recycle bin is some kind of virtual file... but i dont understand the concept given in the MSDN library about it.. i wounder if there is a built in function or do i need to create it... and if i have to create it.. what do i need to know... for such operation???
    Artist get ofended by bad Art, I get ofended by bad programming...

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    VB Code:
    1. 'This program needs a Common Dialog Box, named CDBox.
    2. '  (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
    3. '   and select Microsoft Common Dialog control)
    4. Private Type SHFILEOPSTRUCT
    5.     hWnd As Long
    6.     wFunc As Long
    7.     pFrom As String
    8.     pTo As String
    9.     fFlags As Integer
    10.     fAborted As Boolean
    11.     hNameMaps As Long
    12.     sProgress As String
    13. End Type
    14. Private Const FO_DELETE = &H3
    15. Private Const FOF_ALLOWUNDO = &H40
    16. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    17. Private Sub Form_Load()
    18.     Dim SHFileOp As SHFILEOPSTRUCT
    19.     'Set the dialog's title
    20.     CDBox.DialogTitle = "Select a file to delete ..."
    21.     'Set the dialog's filter
    22.     CDBox.Filter = "All Files (*.*)|*.*"
    23.     'Show the 'Open File' dialog
    24.     CDBox.ShowOpen
    25.     With SHFileOp
    26.         'Delete the file
    27.         .wFunc = FO_DELETE
    28.         'Select the file
    29.         .pFrom = CDBox.filename
    30.         'Allow 'move to recycle bn'
    31.         .fFlags = FOF_ALLOWUNDO
    32.     End With
    33.     'perform file operation
    34.     SHFileOperation SHFileOp
    35.     MsgBox "The file '" + CDBox.filename + "' has been moved to your Recycling Bin !", vbInformation + vbOKOnly, App.Title
    36. End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    Somewhere in Time
    Posts
    23

    thanx... =:O)

    Thank you dude... been trying to do this for the past 2weeks....
    Thanx alot.... =:OD
    Artist get ofended by bad Art, I get ofended by bad programming...

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type SHFILEOPSTRUCT
    4.     hWnd As Long
    5.     wFunc As Long
    6.     pFrom As String
    7.     pTo As String
    8.     fFlags As Integer
    9.     fAborted As Boolean
    10.     hNameMaps As Long
    11.     sProgress As String
    12. End Type
    13.  
    14. Private Const FO_DELETE = &H3
    15. Private Const FOF_ALLOWUNDO = &H40
    16. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    17.  
    18. Private Sub Command1_Click()
    19.     Dim sFile2Delete As String
    20.     'file to delete
    21.     sFile2Delete = "C:\TEST.BMP"
    22.     'doit
    23.     ShellDeleteFile sFile2Delete, FOF_ALLOWUNDO
    24. End Sub
    25.  
    26. Public Sub ShellDeleteFile(sFile As String, ActionFlag As Long)
    27.     Dim SHFileOp As SHFILEOPSTRUCT
    28.     Dim r As Long
    29.     sFile = sFile & Chr$(0)
    30.     With SHFileOp
    31.         .wFunc = FO_DELETE
    32.         .pFrom = sFile
    33.         .fFlags = ActionFlag
    34.     End With
    35.     r = SHFileOperation(SHFileOp)
    36. End Sub
    -= a peet post =-

  5. #5
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    what you playing at peet?!

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    ouch!

    "King of Most things..." have already been here
    -= a peet post =-

  7. #7
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    Somewhere in Time
    Posts
    23

    Talking thanx again...

    Thanx again... =:O)

    Anychance having a smaller code... just kidding.... =:OP
    Artist get ofended by bad Art, I get ofended by bad programming...

  9. #9
    Fanatic Member
    Join Date
    Aug 2001
    Posts
    746
    how can i send a file to the recycle bin without asking for confirmation?
    FlameWave Technologies - internet tools

  10. #10
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type SHFILEOPSTRUCT
    4.     hWnd As Long
    5.     wFunc As Long
    6.     pFrom As String
    7.     pTo As String
    8.     fFlags As Integer
    9.     fAborted As Boolean
    10.     hNameMaps As Long
    11.     sProgress As String
    12. End Type
    13.  
    14. Private Const FO_DELETE = &H3
    15. Private Const FOF_ALLOWUNDO = &H40
    16. Private Const FOF_NOCONFIRMATION As Long = &H10
    17. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    18.  
    19. Private Sub Command1_Click()
    20.     Dim sFile2Delete As String
    21.     'file to delete
    22.     sFile2Delete = "C:\TEST.BMP"
    23.     'doit
    24.     ShellDeleteFile sFile2Delete, FOF_ALLOWUNDO + FOF_NOCONFIRMATION
    25. End Sub
    26.  
    27. Public Sub ShellDeleteFile(sFile As String, ActionFlag As Long)
    28.     Dim SHFileOp As SHFILEOPSTRUCT
    29.     Dim r As Long
    30.     sFile = sFile & Chr$(0)
    31.     With SHFileOp
    32.         .wFunc = FO_DELETE
    33.         .pFrom = sFile
    34.         .fFlags = ActionFlag
    35.     End With
    36.     r = SHFileOperation(SHFileOp)
    37. End Sub
    -= a peet post =-

  11. #11
    Fanatic Member
    Join Date
    Aug 2001
    Posts
    746
    thx works great.
    FlameWave Technologies - internet tools

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