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

时间:2017-08-06 20:20:59   收藏:0   阅读:230

 

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

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);
}

原文:http://www.cnblogs.com/zhoujgssp/p/7295769.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!