Empty/Get size of Recycle Bin

Can get the size in bytes + count of items in recycle bin or empty it.
It works by calling SHQueryRecycleBin and SHEmptyRecycleBin from Shellapi.h which is derived from shell32.dll

#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <Shellapi.h>

void help() {
   printf(
      "rbin - by Jakash3\n"
      "Empties or queries information about the Recycle Bin\n"
      "Usage: rbin (info | empty (-d | -p | -s))\n"
      "info   Output size in bytes and number of items in recycle bin\n"
      "empty  Empty the recycle bin {\n"
      "          -d   Show confirmation dialog box\n"
      "          -p   Show progress dialog\n"
      "          -s   Play sound when complete\n"
      "       }\n"
   );
}

int main(int argc, char *argv[]) {
   if (argc<=1) { help(); return 1; }
   if (!strcmp(argv[1],"info")) {
      SHQUERYRBINFO binfo;
      binfo.cbSize=sizeof(SHQUERYRBINFO);
      HRESULT res=SHQueryRecycleBin(0,&binfo);
      if (res==S_OK) {
         printf(
            "Bytes:%I64d\n"
            "Count:%I64d\n",
            binfo.i64Size,
            binfo.i64NumItems
         );
      } else {
         printf("Error getting recycle bin information.\n");
      }
   } else if (!strcmp(argv[1],"empty")) {
      int dwFlags=SHERB_NOCONFIRMATION|SHERB_NOPROGRESSUI|SHERB_NOSOUND;
      int i;
      for (i=0;i<argc;i++) {
         if (i>=2) {
            if (!strcmp(argv[i],"-d")) {
               dwFlags=dwFlags^SHERB_NOCONFIRMATION;
            } else if (!strcmp(argv[i],"-p")) {
               dwFlags=dwFlags^SHERB_NOPROGRESSUI;
            } else if (!strcmp(argv[i],"-s")) {
               dwFlags=dwFlags^SHERB_NOSOUND;
            }
         }
      }
      SHEmptyRecycleBin(0,0,dwFlags);
   } else {
      help();
      return 1;
   }
return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: