c#利用批处理清理大目录

 

//先保存一个批处理.再执行;

public static void mSaveBatAndExe(string strPath)
{
if (!Directory.Exists(strPath))
{
return;
}
if (!strPath.EndsWith("\\"))
{
strPath += "\\";
}
string fileName = strPath + "remove.bat";

StreamWriter bat = new StreamWriter(fileName, false, Encoding.Default);

bat.WriteLine("cd..");

bat.WriteLine(string.Format("del /f /s /q {0}\\*.*", strPath));


bat.WriteLine("echo OK");
// bat.WriteLine(string.Format("del \"{0}\" /q", strPath));
// bat.WriteLine(string.Format("del \"{0}\" /q", fileName));
// bat.WriteLine(string.Format("rd \"{0}\" /q", strPath.Substring(0, strPath.LastIndexOf('\\'))));

bat.Close();
ProcessStartInfo info = new ProcessStartInfo(fileName);
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
}

posted @ 2017-08-06 19:56  宋世鹏宇宙信息  阅读(240)  评论(0编辑  收藏  举报