c#中的robocopy不会复制数据

时间:2017-03-22 00:10:05

标签: c#

我的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;
        }

1 个答案:

答案 0 :(得分:1)

我敢打赌你的目的地路径有一个空间。尝试使用引号封装源路径和目标路径:

 p.StartInfo.Arguments = string.Format("/C ROBOCOPY \"{0}\" \"{1}\"",
             sourceTextBox.Text , destinationTextBox.Text, "CopyFilesForm.exe");

另外,为了清晰起见," CopyFilesForm.exe"从不使用参数,但我认为它只是一个调试剩余的?