原文作者:aircraft
原文链接:https://www.cnblogs.com/DOMLX/p/17270147.html
代码如下,直接通过cmd调用dos命令进行删除
public static void DeleDir(string DirPath)
{
if (!Directory.Exists(DirPath))
return;
//Parent不能是盘的根目录
DirectoryInfo Parent = Directory.GetParent(DirPath);
if(Parent!=null)
{
ProcessStartInfo Info = new ProcessStartInfo();
Info.Arguments = $"/C rmdir /s /q \"{DirPath}\"";
Info.WindowStyle = ProcessWindowStyle.Hidden;
Info.CreateNoWindow = true;
Info.FileName = "cmd.exe";
Process.Start(Info);
}
else
{
//不能为根目录或者null路径
}
}
若有兴趣交流分享技术,可关注本人公众号,里面会不定期的分享各种编程教程,和共享源码,诸如研究分享关于c/c++,python,前端,后端,opencv,halcon,opengl,机器学习深度学习之类有关于基础编程,图像处理和机器视觉开发的知识
