我正在尝试编写一个 .NET 控制台应用程序,该应用程序将使用 xcopy 复制比 x 天新的文件,同时保持原始日期创建时间戳。我目前有这个作为我的命令:
/// <summary>
/// Performs Copy and Verification using xcopy
/// </summary>
/// <returns>true if success, false otherwise</returns>
internal bool CopyAndVerify()
{
string date = @"d:" + time.ToString("MM/dd/yyyy");
date = date.Replace('/', '-');
date = date.Insert(0, "/");
Process exeProcess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.FileName = "xcopy.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "\"" + source + "\"" + " " + "\"" + dest + "\"" + @" /v " + date + " /i /s /r /h /y /z";
try
{
using (exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch (Exception)
{
return false;
}
return true;
}
该代码执行复制和验证,但是当我测试时,我发现修改文件夹/子文件夹日期和创建日期是复制的时间。我究竟做错了什么?