Reputation: 42379
In case I want to programatically clear the recycle bin under Windows, how to implement that?
Does IFileOperation
help?
Upvotes: 5
Views: 3185
Reputation: 26209
You can use SHEmptyRecycleBin()
function from shell32.dll
library to achieve this.
Upvotes: 5
Reputation: 815
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
}
}
}
Upvotes: 4