Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleSee how many items are in the recycle bin and delete them
DescriptionThis example shows how to see how many items are in the recycle bin and delete them in Visual Basic 6. It uses the SHQueryRecycleBin and SHEmptyRecycleBin API functions.
Keywordsrecycle bin, wastebasket, waste basket
CategoriesSoftware Engineering, Miscellany, Files and Directories
 
Thanks to Martijn Coppoolse.

Subroutine QueryRecycleBin uses the SHQueryRecycleBin API function to return the number of items and the size of the items in the recycle bin.

 
Public Sub QueryRecycleBin(Optional ByVal RootPath As _
    String = vbNullString, Optional ByRef Size As Variant, _
    Optional ByRef NumItems As Variant)
Dim pQRBI As SHQUERYRBINFO
  
  'Make sure variants are initialized to
  ' Decimal subtype (largest numeric)
  Size = CDec(0)
  NumItems = CDec(0)
  
  With pQRBI
    .cbSize = Len(pQRBI)

    SHQueryRecycleBin RootPath, pQRBI
    
    'The Currency data type is the only pure
    ' 64-bits numeric data type VB has, but
    ' it inserts a comma at the fourth
    ' position from the right...
    'Let's correct this!
    Size = .i64Size * 10000
    NumItems = .i64NumItems * 10000
  End With
End Sub
 
The program uses the SHEmptyRecycleBin API function to empty the recycle bin.
 
Public Declare Function EmptyRecycleBin Lib "shell32" Alias _
    "SHEmptyRecycleBinA" ( _
    Optional ByVal hWnd As Long = 0, _
    Optional ByVal pszRootPath As String = vbNullString, _
    Optional ByVal dwFlags As rbEmptyBinEnum = 0) _
As Long
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated