Copy only files that are newer

Posted by ErocM on Stack Overflow See other posts from Stack Overflow or by ErocM
Published on 2012-10-10T21:28:21Z Indexed on 2012/10/10 21:37 UTC
Read the original article Hit count: 201

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about copy