I need to inspect all files within a Repository periodically and compare its LastAccessTime in order to know when was the last time that file was used (accessed, modified and/or updated).
I've already been tried with File.GetLastAccessTime() and FileInfo.LastAccessTime, but I always get the same DateTime after open/close it, or read it.
How could I know when a file has been used?
Thanks!
string path = System.Environment.CurrentDirectory + "/testing/doc2.txt"
Console.WriteLine("--------------------------------------");
Console.WriteLine("GetLastAccessTime {0}", File.GetLastAccessTime(path));
Console.WriteLine("GetLastAccessTimeUtc {0}", File.GetLastAccessTimeUtc(path));
Console.WriteLine("Directory.GetLastAccessTime {0}", Directory.GetLastAccessTime(path));
FileInfo fi = new FileInfo(path);
Console.WriteLine("fi.LastAccessTime {0}", fi.LastAccessTime);
output:
GetLastAccessTime 12/18/2018 11:41:15 AM
GetLastAccessTimeUtc 12/18/2018 4:41:15 PM
Directory.GetLastAccessTime 12/18/2018 11:41:15 AM
fi.LastAccessTime 12/18/2018 11:41:15 AM
--------------------------------------
GetLastAccessTime 12/18/2018 11:41:15 AM
GetLastAccessTimeUtc 12/18/2018 4:41:15 PM
Directory.GetLastAccessTime 12/18/2018 11:41:15 AM
fi.LastAccessTime 12/18/2018 11:41:15 AM