views:

165

answers:

2

Trying this I have found a strange problem: Delete an old file. Create a new file and name it the same as the old file. Then the "created time" property of the new file is set to the "created time" of the old file. Why is that happens? And how of course? It seems that the directory does not delete the old file's entry and if a new file gets created in the same folder then the old entry is used.

A: 

The NT file system does not delete a file when you think it does. When you delete a file on an NT file system the operating system simply marks the disk space that file occupied as available. The file will not be truly deleted until another file is written to that location on disk.

As to why Windows would think it was the same exact file I believe this is due to the fact that the file was empty when you deleted it so creating a new file in the same location with the same name and the same (empty) contents makes Windows think it is in fact the same file. I would consider this to be a bug.

As a side note, the fact that Windows handles file deletes in this way is the very reason that you are able to use file-recovery utilities to recover deleted files.

Andrew Hare
+5  A: 

It's due to file system tunnelling, as explained by Raymond Chen:

"Why does tunneling exist at all?

When you use a program to edit an existing file, then save it, you expect the original creation timestamp to be preserved, since you're editing a file, not creating a new one. But internally, many programs save a file by performing a combination of save, delete, and rename operations (such as the ones listed in the linked article), and without tunneling, the creation time of the file would seem to change even though from the end user's point of view, no file got created.

As another example of the importance of tunneling, consider that file "File with long name.txt", whose short name is say "FILEWI~1.TXT". You load this file into a program that is not long-filename-aware and save it. It deletes the old "FILEWI~1.TXT" and creates a new one with the same name. Without tunnelling, the associated long name of the file would be lost. Instead of a friendly long name, the file name got corrupted into this thing with squiggly marks. Not good."

Ian Kemp
+1 for the actual explanation of what's going on. And for linking to Raymond Chen.
OregonGhost