我的robocopy无法运行..我有以下代码,我没有收到任何错误。请问你能帮忙吗?
try
{
System.Diagnostics.Process p = new Process();
p.StartInfo.Arguments = string.Format("/C ROBOCOPY {0} {1}",
sourceTextBox.Text , destinationTextBox.Text, "CopyFilesForm.exe");
p.StartInfo.FileName = "CMD.EXE";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
p.Start();
p.WaitForExit();
if (p.HasExited)
{
MessageBox.Show("Copy Successful");
}
}
catch
{
MessageBox.Show("Error. Please try closing the application and try again.");
throw;
}
答案 0 :(得分:1)
我敢打赌你的目的地路径有一个空间。尝试使用引号封装源路径和目标路径:
p.StartInfo.Arguments = string.Format("/C ROBOCOPY \"{0}\" \"{1}\"",
sourceTextBox.Text , destinationTextBox.Text, "CopyFilesForm.exe");
另外,为了清晰起见," CopyFilesForm.exe"从不使用参数,但我认为它只是一个调试剩余的?