我使用以下代码将文件夹从一个路径复制到另一个路径。如果复制文件已存在,则为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/
答案 0 :(得分:1)
http://support.microsoft.com/kb/240268处的注释将/ R描述为覆盖只读文件的附加参数。你试过添加吗?
答案 1 :(得分:1)
xcopy
应覆盖文件(/Y
标志会禁止提示进行确认)。可能是目标文件是只读的吗?在这种情况下,您还需要指定/R
标志。