I'm copying files generated by an application periodically to my PC from a network location,but sometimes the files are still be written when I copy them.
How can I tell if the file is still be written to?
public void copyFile(string source, string destination)
{
DirectoryInfo dir = new DirectoryInfo(s ource);
FileInfo[] files = dir.GetFiles();
foreach (FileInfo f in files)
{
DateTime currentTime = DateTime.Now;
DateTime tolerance = currentTime.Sub tract(new TimeSpan(0, 5, 0));
if (tolerance.Comp areTo(f.LastWri teTime) > 0)
{
f.CopyTo(destin ation + "" + f.Name, true);
}
}//end of foreach
}
How can I tell if the file is still be written to?
public void copyFile(string source, string destination)
{
DirectoryInfo dir = new DirectoryInfo(s ource);
FileInfo[] files = dir.GetFiles();
foreach (FileInfo f in files)
{
DateTime currentTime = DateTime.Now;
DateTime tolerance = currentTime.Sub tract(new TimeSpan(0, 5, 0));
if (tolerance.Comp areTo(f.LastWri teTime) > 0)
{
f.CopyTo(destin ation + "" + f.Name, true);
}
}//end of foreach
}
Comment