I used FileInfo.LastWriteTime to find out when was the last time a particular file was modified, say, "c: \ temp \ test_file.txt".
It works great when someone really opens the file, makes changes, and then saves - FileInfo.LastWriteTime for this path is updated with the time when the file was changed.
But what happens in the following scenario:
Copy the file with the same name, but with different contents from another place on the disk, and paste it into the folder "c: \ temp" (override the existing file) - the file "c: \ temp \ test_file". txt "was actually changed (overridden by a file with the same name but with different content), but the LastWriteTime of the file" c: \ temp \ test_file.txt "is not the moment when it was redefined, but actually" LastWriteTime " file that we copied, and may be much earlier than the moment when it was redefined.
In case I need to know the moment when the file was overridden, is there another way and don’t offer such solutions as registering in FileChange events - I’m looking for a solution in which I don’t need to constantly support the program as a service - my application may not run all the time, and I need to know when the file was overridden, even if that moment was when my application was closed.
Liorp source share