C#实现清空回收站的方法
程序员文章站
2023-01-10 16:55:32
本文实例讲述了c#实现清空回收站的方法。分享给大家供大家参考。具体实现方法如下:
using system;
using system.collections....
本文实例讲述了c#实现清空回收站的方法。分享给大家供大家参考。具体实现方法如下:
using system; using system.collections.generic; using system.linq; using system.text; using system.runtime.interopservices; namespace app { class clearrecycle { [dllimportattribute("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; /// <summary> /// 清空回收站 /// </summary> /// <param name="tip">是否提示</param> /// <param name="form">当前窗体,一般传入this</param> public static void clear(bool tip, system.windows.forms.form form) { system.windows.forms.dialogresult result = system.windows.forms.dialogresult.no; if (tip) result = system.windows.forms.messagebox.show("确定要清空回收站吗?", "友情提示", system.windows.forms.messageboxbuttons.yesno, system.windows.forms.messageboxicon.information); else result = system.windows.forms.dialogresult.yes; if (result == system.windows.forms.dialogresult.yes) { shemptyrecyclebin(form.handle, "", sherb_noconfirmation + sherb_noprogressui + sherb_nosound); } } } }
希望本文所述对大家的c#程序设计有所帮助。