November 22nd, 2005

Why is a drive letter permitted in front of UNC paths (sometimes)?

A little-known quirk is that the file system accepts and ignores a drive letter in front of a UNC path. For example, if you have a directory called \\server\share\directory, you can say

dir P:\\server\share\directory
and the directory will be listed to the screen. The leading P: is ignored.

Why is that?

Rewind to 1984 and the upcoming release of MS-DOS 3.1, which added networking support. Up to this point, all fully-qualified file specifications consisted of three components: A drive letter, a path, and a file name. Many programs relied on this breakdown and did things like “helpfully” prepend a drive letter if it looks like you “forgot” one. For example, if you told it to save the results to \\server\share\file.txt it would say, “Oh dear, that’s not good, the user forgot the drive letter! I’ll put the current drive in front to make things better,” resulting in C:\\server\share\file.txt. Other programs would prompt you with “Please enter a drive letter”, and you couldn’t say “No, there’s no drive letter, just take the path and use it.” They insisted on a drive letter, and you darn sure better give them one.

(Compare the Unix programs that “helpfully” rewrite //server/volume/file as /server/volume/file because they “know” that consecutive slashes collapse, unaware of the special exception for two leading slashes.)

In order to retain compatibility with programs that provided this sort of “unwanted help”, the designers of the networking support in MS-DOS decided to allow the strange syntax C:\\server\share\directory and treat it as if the drive letter simply weren’t there. Some (but not all) of this quirk of path parsing persists today.

[Raymond is currently away; this message was pre-recorded.]

Topics
History

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.