When would the "." and ".." entries in a dir listing differ? (I understand they represent two different directories, but they always list identically with the same date and time in a default dir command. Do they ever differ?)

3 Answers
3

They're using the date of the current directory for both. If you start in C:\Users\Chris (say) you might get the above. But when you go up to C:\Users you get:

26/07/2011 21:20 <DIR> .
26/07/2011 21:20 <DIR> ..

So the date of .. in the first case is not the same as the date of . in the second. Which is apparently wrong as they are (or should be) the same directory. However, . and .. are references to the current and parent directory and are both created at the same time - when the directory was created - so it's actually correct (thanks to Synetech inc for pointing this out)

The only time the timestamps would be different is if one or other of . or .. were recreated.

The original answer:

. means the current directory.

.. means the parent directory.

So under normal circumstances they are always different.

The only time they yield the same result is when you are at the root of the disk. So at C:\>dir . and dir .. produce the same output.

That’s wrong, because .. not given the timestamp of the parent directory, it is given the timestamp of the current directory. This is because . and .. are both created when the directory is created.
–
SynetechSep 13 '11 at 22:06

No, they will always be the same. Because these are directories, not files, they are handled slightly differently (in fact, they are not even normal directories, they are pointers as eL01 said, so they are handled even more differently than normal directories).

When you create a directory, two entries are automatically created:

. points to the newly created directory

.. points to the the new directory’s parent

Obviously . will have the current date and time that the directory is created, and while it may seem logical for the timestamp of the parent directory to be copied to .., that is not how it works. When you create a new directory, both of the pointers receive the current date and time. This is the case from DOS through Windows 7 on both FAT* and NTFS.

+1 since it seems you were the one coming up with the answer ChrisF is now presenting ;-)
–
Jonas HeidelbergSep 13 '11 at 22:40

@Jonas, actually, ChrisF’s answer makes the same mistaken assumption that most people would: that .. would have the timestamp of the parent. (I would not be surprised if some day, a new file-system—WinFS?—were to finally do it that way).
–
SynetechSep 13 '11 at 23:01

I actually can't give you proof, but I think:
Every directory has a list of directories and files it contains. To make it possible to use relative paths every directory needs those two pointers - one to itself . and the other directory one level above .. - those two pointers are just created on the time the directory itself is created.

So the timestamp of .. is actually not the timestamp of the directory above but the timestamp of the pointer to the directory above.