清空回收站中所有文件

实现效果:

  

知识运用:

  系统API函数SHEmptyRecycleBin  //清空回收站中的文件

  [DllImport("shell32.dll")] 
  private static extern int SHEmptyRecycleBin(IntPtr handle,string root,int falgs);

  handle  //父窗口句柄  root //要清空回收站的地址  为null时 清楚所有驱动位置    falgs   //功能参数

实现代码:

        private const int SHERB_NOCONFIRMATION=0x000001;        //删除时没有确认对话
        private const int SHERB_NOPROGRESSUI = 0x000002;        //不显示进度条
        private const int SHERB_NOSOUND=0x000004;               //完毕时不播放声音
        [DllImport("shell32.dll")]                                      //声明API函数
        private static extern int SHEmptyRecycleBin(IntPtr handle,string root,int falgs);

        private void button1_Click(object sender, EventArgs e)
        {                                                       //清空回收站
            SHEmptyRecycleBin(this.Handle,"",SHERB_NOCONFIRMATION+SHERB_NOPROGRESSUI+SHERB_NOSOUND);
        }

  

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10217638.html