In case I want to programatically clear the recycle bin under Windows, how to implement that?
Does IFileOperation
help?
You can use SHEmptyRecycleBin()
function from shell32.dll
library to achieve this.
Full example:
using System;
using System.Runtime.InteropServices;
class Program
{
enum RecycleFlags : uint
{
SHERB_NOCONFIRMATION = 0x00000001,
SHERB_NOPROGRESSUI = 0x00000002,
SHERB_NOSOUND = 0x00000004
}
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
static extern uint SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath, RecycleFlags dwFlags);
static void Main(string[] args)
{
uint result = SHEmptyRecycleBin(IntPtr.Zero, null, 0);
if (result == 0)
{
//OK
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With