Results 1 to 8 of 8

Thread: [RESOLVED] Get the number of items or size of items in the recycle bin

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586

    Resolved [RESOLVED] Get the number of items or size of items in the recycle bin

    I've got some old code of mine that I'm going back to and updating a little bit. On one part of it I need to check if there are any items in the recycle bin or not.

    This is the code I was using to accomplish this:

    vbcode Code:
    1. Private Declare Function SHQueryRecycleBin Lib "shell32.dll" Alias "SHQueryRecycleBinA" (ByVal pszRootPath As String, ByRef pSHQueryRBInfo As SHQUERYRBINFO) As Long
    2.     Private Structure ULARGE_INTEGER
    3.         Dim LowPart As Integer
    4.         Dim HighPart As Integer
    5.     End Structure
    6.     Private Structure SHQUERYRBINFO
    7.         Dim cbSize As Integer
    8.         Dim i64Size As ULARGE_INTEGER
    9.         Dim i64NumItems As ULARGE_INTEGER
    10.     End Structure
    11.     Public Function IsRecycleBinEmpty() As Boolean
    12.         Dim SHQBI As SHQUERYRBINFO
    13.  
    14.         SHQBI.cbSize = Marshal.SizeOf(SHQBI)
    15.         SHQueryRecycleBin("", SHQBI)
    16.  
    17.         If (SHQBI.i64Size.LowPart <> LastRecycleBinSize) Then
    18.             MsgBox(SHQBI.i64Size.HighPart.ToString + " - " + SHQBI.i64Size.LowPart.ToString + " - " + SHQBI.i64NumItems.LowPart.ToString + " - " + SHQBI.i64NumItems.HighPart.ToString)
    19.             LastRecycleBinSize = SHQBI.i64Size.LowPart
    20.         End If
    21.         End
    22.  
    23.         If (SHQBI.i64NumItems.LowPart) Then
    24.             IsRecycleBinEmpty = False
    25.         Else
    26.             IsRecycleBinEmpty = True
    27.         End If
    28.     End Function

    The msgbox and end is just in there for debugging purposes. This always returns all 0s, even when I know that there is something in the recycle bin.

    Anyone have any ideas on what I'm doing wrong here?

    Thanks!

  2. #2
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Get the number of items or size of items in the recycle bin

    Shouldn't

    Code:
    SHQBI.cbSize = Marshal.SizeOf(SHQBI)
    Be

    Code:
    SHQBI.cbSize = Marshal.SizeOf(typeof(SHQUERYRBINFO))
    Can't you just check CInt(SHQBI.i64NumItems) = 0 and return True/False based on that?

    Here's an alternate solution that you may find helpful: http://www.dreamincode.net/forums/to...bin-with-c%23/

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Get the number of items or size of items in the recycle bin

    here's my solution:
    Attached Files Attached Files

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586

    Re: Get the number of items or size of items in the recycle bin

    MattP, doing it that way just complains about SHQUERYBINFO being a type and unable to be used in an expression.

    .paul., that looks just much like my code as far as I'm seeing (except you storing the variables in another custom type "details"), but mine doesn't work. What OS are you running on that it is working for you? I'm running Windows 7, and no matter how many items or what size the items are in my recycle bin, both LowPart and HighPart on the NumOfItems and Size is always 0.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Get the number of items or size of items in the recycle bin

    i wrote it in vb2005.
    as far as i can remember it worked in xp, but definitely in vista + win7

    have you tried setting your target cpu to x86?

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Get the number of items or size of items in the recycle bin

    looks like you found the same example i found years ago

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586

    Re: Get the number of items or size of items in the recycle bin

    Had target cpu set to any cpu. Setting it to x86 indeed works, but causes other problems in my code.

    My project is a shortcut bar similar to the one that came with Microsoft Office 2000, gives me my desktop icons in a nice little bar that sits up in the title bar area. I usually hide my desktop icons for a clean desktop and use this bar for launching applications.

    With the target cpu set to x86, it can't correctly fetch the icon of any specifically 64 bit compiled software. There may be other problems too, that is just the first thing that I noticed. I will play with this some more though, as one of the problems I want to fix is something I did is making it reference the actual file instead of the shortcut to the file, so if I wanted to delete just a shortcut I have to unhide my icons and delete the shortcut. The way I have it configured if I try to delete from the system menu I call upon when right clicking the icon on my bar, it will delete the actual target executable file.

    But, since I prefer this to be a 64 bit compile, does anyone have a method of making this work with a x64 target cpu?

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586

    Re: Get the number of items or size of items in the recycle bin

    Ok, found a way to do this while keeping my target cpu as any cpu.

    Added system32/shell32.dll as a reference and then:
    Code:
        Public Function IsRecycleBinEmpty() As Boolean
            Dim Shell As New Shell32.Shell
    
            Dim RBin As Shell32.Folder = Shell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfBITBUCKET)
    
            If RBin.Items.Count Then
                IsRecycleBinEmpty = False
            Else
                IsRecycleBinEmpty = True
            End If
        End Function
    Thanks for the help guys, and thanks for the link MattP, that is where I got the idea to do it this way from.

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