Copy only files that are newer
- by ErocM
I am currently using this code:
if (!Directory.Exists(command2)) Directory.CreateDirectory(command2);
if (Directory.Exists(vmdaydir)) Directory.Delete(vmdaydir,true);
if (!Directory.Exists(vmdaydir)) Directory.CreateDirectory(vmdaydir);
var dir = Path.GetDirectoryName(args[0]);
sb.AppendLine("Backing Up VM: " + DateTime.Now.ToString(CultureInfo.InvariantCulture));
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(dir, vmdaydir);
sb.AppendLine("VM Backed Up: " + DateTime.Now.ToString(CultureInfo.InvariantCulture));
As you can see, I am deleting the directory, then I am copying the folder back. This is taking way to long since the directory is ~80gb in size. I realized that I do not need to copy all the files, only the ones that have changed.
How would I copy the files from one folder to another but only copying the files that are newer? Anyone have any suggestions?
==== edit ====
I assume I can just do a file compare of each file and then copy it to the new directory, iterating through each folder/file? Is there a simpler way to do this?