public bool ExecuteCmd(string argm)
{
//开始创建文件
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
try
{
p.Start();
p.StandardInput.WriteLine(argm);
p.Close();
return true;
}
catch
{
return false;
}
}
调用:string str_attrib = string.Format("attrib -R -H -A -S \"{0}\\*.*\" /S /D",folder);
ExecuteCmd(str_attrib); //去除文件夹及其子目录的隐藏,只读属性等
ExecuteCmd(@"md d:\abc\mydir"); //建目录