Ghost file remains alive when deleted and recreated

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.

Answers


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


Try to force the refresh of your FileInfo (because data are cached):

var f = new FileInfo("hello");
f.Refresh(); // Force to read all props again
Console.WriteLine("{0} {1}ms", f.CreationTime, f.CreationTime.Millisecond);

Need Your Help

Seemingly defined javascript variable throws undefined error

javascript scope undefined

Given the following code, I'm not sure why I can retrieve longAndObscureVariableName but not anotherLongObscureVariableName. Can you explain, and show how I could make anotherLongObscureVariableName

Lime Survey after user logged in with his token to participate in survey, a separate session is maintained for users?

php yii yii2 limesurvey

After User logged in with his token to participate in the survey. A separate logged in session is created in the lime survey application ??