C#删除路径到回收站

引用命名空间

Microsoft.VisualBasic.FileIO

 

string path = "文件或文件夹路径";
// 检查指定路径是文件还是目录
if (File.Exists(path))
{
    FileSystem.DeleteFile(path, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
}
else if (Directory.Exists(path))
{
    FileSystem.DeleteDirectory(path, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
}

 

posted @ 2024-04-24 17:49  太阳底下淋雨  阅读(45)  评论(0编辑  收藏  举报