none
How to display Recycle Bin size & Contents?

    Question

  • So far I can access the Recycle Bin to empty it with this:

    #Region "Empty Recycle Bin (SUB)"
        Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hWnd As Int32, ByVal pszRootPath As String, ByVal dwFlags As Int32) As Int32
        Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Int32
        Private Const SHERB_NOCONFIRMATION = &H1
        Private Const SHERB_NOPROGRESSUI = &H2
        Private Const SHERB_NOSOUND = &H4


        Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
            SHEmptyRecycleBin(Me.Handle.ToInt32, vbNullString, SHERB_NOCONFIRMATION + SHERB_NOSOUND)
            SHUpdateRecycleBinIcon()
            MsgBox("Your Recycle Bin Is Now Empty", MsgBoxStyle.Information, "Recycle Bin")
        End Sub

    #End Region

    but I need to display the size of the contents & contents in the Recycle Bin... Any help is appreciated much,
    and Thanks in Advanced...
    Monday, January 04, 2010 11:11 PM

Answers

  • Hi, Tj
    I think you are not supposed to convert native code to managed code, this must be result great errors due to there different class library.
    JohnWein has given you a perfectly answer,  especially this link
    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/05e3628d-5d08-4cea-8821-d5302139cc0d/
    Here I will show you how to get the information of all the items in recycle by Automation.
    We must add Shell32.dll Reference first, which is loacated in %SystemRoot%\system32\shell32.dll.
    Here is the code that retrieves all the items and its size in recycle, we use recursion to get the folder size in the recycle.
    (Please notice this is a console application)


    Imports
    Shell32

    Module Module1

        ' %SystemRoot%\system32\shell32.dll

        Sub Main()

            Dim shl As Shell = New Shell()

            'Get Recycler folder

            Dim Recycler As Folder = shl.NameSpace(10)

            For Each FI As FolderItem2 In Recycler.Items()

                Console.WriteLine("FileName:{0}     Size:{1}", FI.Name, getSize(FI))

            Next

        End Sub

        'Use recursion to Get the size of the folderItem

        Function getSize(ByVal FI As FolderItem) As Int32

            If (FI.IsFolder = False) Then

                Return FI.Size

            End If

            Dim fd As Folder = FI.GetFolder()

            Dim sumSize As Int32 = 0

            For Each FI2 As FolderItem2 In fd.Items()

                sumSize = sumSize + getSize(FI2)

            Next

            Return sumSize

        End Function

     

    End Module


    If you have anything unclear feel free to let me know.
    Thanks
    Chao
     
    Friday, January 08, 2010 7:09 AM

All replies

  • Search MSDN for "johnwein recycle".  Most code is in C#.   Use a converter if you need VB.  The posts don't address your question directly, but they show how to manipulate the recycle bin as a standard folder.
    • Marked as answer by Chao KuoModerator Monday, January 11, 2010 6:48 AM
    • Unmarked as answer by Tj.. _ Sunday, February 14, 2010 2:03 AM
    Monday, January 04, 2010 11:41 PM
  • Thanks  JohnWein

    Ive tried converting This but it didnt work for me to many errors... I converted with Tangible Instant VB .
    Monday, January 04, 2010 11:53 PM
  • Hi, Tj
    I think you are not supposed to convert native code to managed code, this must be result great errors due to there different class library.
    JohnWein has given you a perfectly answer,  especially this link
    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/05e3628d-5d08-4cea-8821-d5302139cc0d/
    Here I will show you how to get the information of all the items in recycle by Automation.
    We must add Shell32.dll Reference first, which is loacated in %SystemRoot%\system32\shell32.dll.
    Here is the code that retrieves all the items and its size in recycle, we use recursion to get the folder size in the recycle.
    (Please notice this is a console application)


    Imports
    Shell32

    Module Module1

        ' %SystemRoot%\system32\shell32.dll

        Sub Main()

            Dim shl As Shell = New Shell()

            'Get Recycler folder

            Dim Recycler As Folder = shl.NameSpace(10)

            For Each FI As FolderItem2 In Recycler.Items()

                Console.WriteLine("FileName:{0}     Size:{1}", FI.Name, getSize(FI))

            Next

        End Sub

        'Use recursion to Get the size of the folderItem

        Function getSize(ByVal FI As FolderItem) As Int32

            If (FI.IsFolder = False) Then

                Return FI.Size

            End If

            Dim fd As Folder = FI.GetFolder()

            Dim sumSize As Int32 = 0

            For Each FI2 As FolderItem2 In fd.Items()

                sumSize = sumSize + getSize(FI2)

            Next

            Return sumSize

        End Function

     

    End Module


    If you have anything unclear feel free to let me know.
    Thanks
    Chao
     
    Friday, January 08, 2010 7:09 AM
  • I found this...

    ''' <summary>
     ''' Contains the size and item count information retrieved by the SHQueryRecycleBin function.
     ''' </summary>
     <StructLayout(LayoutKind.Sequential, Pack := 4)> _
     Public Structure SHQUERYRBINFO
     ''' <summary>
     ''' Size of the structure, in bytes. This member must be filled in prior to calling the function.
     ''' </summary>
     Public cbSize As UInteger

     ''' <summary>
     ''' Total size of all the objects in the specified Recycle Bin, in bytes.
     ''' </summary>
     Public i64Size As ULong

     ''' <summary>
     ''' Total number of items in the specified Recycle Bin.
     ''' </summary>
     Public i64NumItems As ULong
     End Structure
    Friday, January 08, 2010 9:24 AM
  • Hello, Tj
    Does your solution works ? If so, I will mark your reply, and my reply and johnwein's reply as answer. If not, please don't insist on your ways, my solution works perfectly well.
    Thanks
    Chao-
    Saturday, January 09, 2010 7:13 AM