What I'm doing
I'm working on a webservice which is copying files from one location to another. Files are being updated(the size should be increased every 3 seconds since there is text added).
1st option:
I'm checking every 10 seconds if any of the files is modified(they are being modified every 5 seconds cca) so I can copy(and overwrite) them to the final destination. Atm I'm using a code which is comparing the last edit time of the file with actual time - some amount of time(1 minute atm).
DateTime lastEditTime = new DateTime();
lastEditTime = File.GetLastWriteTime(myFile);
if (lastEditTime > DateTime.Now.AddMinutes(-1))
{
File.Copy(myFile, newFileName, true);
}
But I think this is kinda bad approach since there might be some time space or something and I won't get some changes.
2nd option
I could check the file sizes(using the FileInfo.Length property probably) of each file in the source directory and compare them to the ones in final destination. This should be ok too since the file sizes should only grow since the text is added only.
3rd option
I read a lot people recommend the FileSystemWatcher but I don't want to miss some changes which might happen - at least I read that at other SO questions(see https://stackoverflow.com/a/240008/2296407).
What is my question?
What is the best option to know if any file was changed(if the file in source is different from file in final destination) in last x mins or seconds cause I don't want to copy everything since there might be a lot of files.
By being best option I mean: is it faster to compare each files sizes or compare the File.GetLastWriteTime(myFile)
with actual time - some time. In the second case ther is also question: How big the time span should be? If I put a big time span I will probably copy more files than I actually need but if I put it low I might miss some changes.
If you have some better options feel free to share them with me!