这不起作用,它找不到del.exe ......
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "del.exe";
p.StartInfo.Arguments = "*.bak";
p.Start();
p.Close();
答案 0 :(得分:3)
你这样做是错误的。您应该使用File.Delete
method代替。
示例代码:
string sourceDir = @"C:\Backups"; // change this to the location of the files
string[] bakList = Directory.GetFiles(sourceDir, "*.bak");
try
{
foreach (string f in bakList)
{
File.Delete(f);
}
}
catch (IOException ioex)
{
// failed to delete because the file is in use
}
catch (UnauthorizedAccessException uaex)
{
// failed to delete because file is read-only,
// or user doesn't have permission
}
答案 1 :(得分:0)
如果您有理由选择执行Directory.GetFiles
处理File.Delete
加上处理?