Saturday, February 21, 2009

[VC++] Programmatically empty the Recycle Bin

Suppose in your program if you are in need of more disk space very first thing you can do is empty the recycle bin. There is a shell function SHEmptyRecycleBin() for emptying the recycle bin. Please see the below code snippet showing the usage.
// Empty Recycle bin.
if( S_OK == SHEmptyRecycleBin( NULL,
NULL,
SHERB_NOCONFIRMATION ))
{
// Successfully emptied
}
You can specify options such as do not show delete progress and do not make sounds specifying respective flags in the last parameter of the function. Specifying drive or folder path as the second parameter will remove only content deleted from those folders.

No comments: