I'm observed a strange problem when using the File.GetLastWriteTime() method to get the last write date and time of the specified directory.
Consider the following code:
// ‘path’ is directory for which need to obtain modification date/time information.
DateTime dtp = File.GetLastWriteTime(path);
DateTime dtf = File.GetLastWriteTime(path+@"\log.txt");
Console.WriteLine($"{path}, dir: {dtp:hh:mm:ss.fff}, file: {dtf:hh:mm:ss.fff}");
Now, when I update the log.txt file, for example, by performing
echo some-text >> "log.txt"
from the command prompt the dtf is updated but the dtp doesn't changed.
The specified directory date and time is changed only if I create a new file or delete some file inside the directory.
Can anyone help me to understand what I missed here?
NOTES:
The same happens when using the
Directory.GetLastWriteTime()method.Used the Windows 10.
The OS doesn't have any registry fixes applied like described in this post: File.GetLastWriteTime seems to be returning 'out of date' value
An explanation that I found in doc is that:
I think is challenging because a file or a directory may in fact be a virtual one or can be a symlink (in Linux).