I just noticed a strange behavior with deleting and re-writing a file : the file creation time does not get updated if the interval is short enough between the two operations.
I ran the following code :
File.Delete("hello");
using(var stream = new StreamWriter("hello"))
{
stream.WriteLine("hello");
}
var f = new FileInfo("hello");
Console.WriteLine("{0} {1}ms", f.CreationTime, f.CreationTime.Millisecond);
If I put a breakpoint on the using(...) line, I can see the file disappearing after the delete, but at the end it will still give me the old creation date. I can even delete the file manually from the explorer and then run this code, it still shows the old creation time.
However, if I wait an undetermined time (around 1 minute) between the deletion and recreation, the creation time is set correctly (works if I wait with the debugger on the breakpoint mentioned above).
Where does this come from ? Is it a documented windows behavior ? Am I forgetting something ?
PS : I’m testing this on windows XP, for what it matters.
This is a known problem/feature in Windows called file tunneling.
Ref:
http://support.microsoft.com/kb/172190
Related:
https://serverfault.com/questions/92757/incorrect-file-creation-date-in-windows-xp-vista
Why Windows sets new created file's "created time" property to old time?
Windows filesystem: Creation time of a file doesn't change when while is deleted and created again