File Date, Time

I have two files:

a:\\update\FileOne.txt

b:\\working\FileOne.txt

I want to be able to check the date and time of both files, if the file on a:\\ is newer then I want to delete b:\\ then copy a:\\ to b:\\

Can anyone point me in the right direction, samples would be good for me.

Thanks in advance



Answer this question

File Date, Time

  • Andrea Williams

    Try this:

    using System.IO;

    ...

    FileInfo file1 = new FileInfo("A:\\update\\FileOne.txt");

    FileInfo file2 = new FileInfo("B:\\working\FileOne.txt");

    if (file1.LastWriteTime > file2.LastWriteTime)

    {

    file1.CopyTo(file2.FullName, true);

    }



  • File Date, Time