0

我使用以下代码将文件夹从一个路径复制到另一个路径。如果复制文件已经存在does not replace the existing file。有什么可用的命令xcopy/replace吗?

private static void ProcessXcopy(string SolutionDirectory, string TargetDirectory)

        {

            // Use ProcessStartInfo class

            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.CreateNoWindow = false;

            startInfo.UseShellExecute = false;

            //Give the name as Xcopy

            startInfo.FileName = "xcopy";

            //make the window Hidden

            startInfo.WindowStyle = ProcessWindowStyle.Hidden;

            //Send the Source and destination as Arguments to the process

            startInfo.Arguments = "\"" + SolutionDirectory + "\"" + " " + "\"" + TargetDirectory + "\"" + @" /e /y /I";

            try

            {

                // Start the process with the info we specified.

                // Call WaitForExit and then the using statement will close.

                using (Process exeProcess = Process.Start(startInfo))

                {

                    exeProcess.WaitForExit();

                }

            }

            catch (Exception exp)

            {

                throw exp;

            }



        }

参考: http ://www.c-sharpcorner.com/UploadFile/jawedmd/xcopy-using-C-Sharp-to-copy-filesfolders/

4

2 回答 2

1

http://support.microsoft.com/kb/240268上的注释将 /R 描述为覆盖只读文件的附加参数。您是否尝试过添加它?

于 2013-07-06T10:38:06.840 回答
1

xcopy默认情况下应该覆盖文件(并且该/Y标志会抑制确认提示)。可能是目标文件是只读的吗?在这种情况下,您还需要指定/R标志。

于 2013-07-06T10:38:31.163 回答