File Date, Time  
Author Message
Can-Ann





PostPosted: Visual C# Language, File Date, Time Top

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



Visual C#5  
 
 
Brendan Grant





PostPosted: Visual C# Language, File Date, Time Top

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);

}