原文作者:aircraft
原文链接:https://cloud.tencent.com/developer/article/2255194
代码如下,直接通过cmd调用dos命令进行删除
代码语言:javascript复制 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路径
}
}