C#清空回收站
曾经用过bat处理回收站,但是效果很不理想(应该是我水平不够吧),后来发现C#可以直接调用系统dll,非常简单。下面是具体函数:
class ClearRecycle { [DllImport("shell32.dll")] private static extern int SHEmptyRecycleBin(IntPtr handle, string root, int falgs); const int SHERB_NOCONFIRMATION = 0x000001; const int SHERB_NOPROGRESSUI = 0x000002; const int SHERB_NOSOUND = 0x000004; public static void Clear(System.Windows.Forms.Form form) { SHEmptyRecycleBin(form.Handle, "", SHERB_NOCONFIRMATION + SHERB_NOPROGRESSUI + SHERB_NOSOUND); } }
调用:
private void button1_Click(object sender, EventArgs e) { ClearRecycle.Clear(this); }
身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。