Click here to Skip to main content
15,898,987 members
Please Sign up or sign in to vote.
1.75/5 (4 votes)
See more:
Basically I want just to check if the Recycle Bin is empty or not. I have found plenty of codes but none work. I want to do this with the API, I do not want to reference the Shell Namespace. With Shell Namespace I got already a working solution now I seek for the API solution. This code I use and it fails, I cannot see why this does not work for me:

C#
StructLayout(LayoutKind.Explicit, Size = 20, Pack = 4)]
        public struct SHQUERYRBINFO
        {
            [FieldOffset(0)]
            public int cbSize;
            [FieldOffset(4)]
            public long i64Size;
            [FieldOffset(12)]
            public long i64NumItems;
        }

        [DllImport("shell32.dll")]
        static extern int SHQueryRecycleBin(string pszRootPath, ref SHQUERYRBINFO pSHQueryRBInfo);

        public static int GetCount()
        {
            SHQUERYRBINFO sqrbi = new SHQUERYRBINFO();
            sqrbi.cbSize = Marshal.SizeOf(typeof(SHQUERYRBINFO));
            int hResult = SHQueryRecycleBin(String.Empty, ref sqrbi);
            if (hResult == 0)
            {
                return (int)sqrbi.i64NumItems;
            }
            return 0;
        }


The return value is not zero the function call itself fails already.
I use Windows 7 64 Bit Pro and VS 2008 with NET 2.0 on an actual Intel Machine with all Windows Updates installed. Maybe 64 Bit is the issue?
Posted

1 solution

Have you tried with Directory.GetFiles(@"C:\$Recycle.bin")?
 
Share this answer
 
Comments
Joan Magnet 22-Mar-15 18:13pm    
I know it isn't what you are looking for but you can encapsulate it using a c# class.

http://stackoverflow.com/questions/3282418/send-a-file-to-the-recycle-bin
Adam Zgagacz 27-Mar-15 13:48pm    
I was wrong. This solution should work in Windows 7/8

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900