XCopy commands to archive files with original date stamp
I am trying to write a .NET console app that will use xcopy to copy over
files newer than x days, while maintaining the original date created
timestamp. I currently have this as my command:
/// <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;
}
The code performs the copy and verification, but then when I test I find
that the Folders/SubFolders date modified and date created is the time of
the copy. What am I doing wrong?
No comments:
Post a Comment