Compartir vía


Windows Confidential

What's in a Filename?

Raymond Chen

EVERYBODY WANTS to know why file extensions are hidden by default. Usually, they ask this question in an accusatory tone, as if suppressing the display of file extensions causes cancer or something.
There are a few different ways of looking at this.

Recall that the extension is just a piece of metadata that encodes the file type, and very little metadata consistently survives all the various modes of file transfer. For example, a .ZIP file saves the file time and filename and file contents. Even worse, sending a file as an attachment preserves only the filename and contents. The filename is overloaded as a dual storage location, multiplexing both the user-assigned name and the type information.

The much-heralded original Mac file system explicitly separated the user-assigned name and the type information. The "filename" in the Mac world was just the user-assigned name, and the type information was stored in metadata. On a Mac, the text under an icon representing a file showed only the user-assigned name. This is frequently pointed out as one of the reasons why a Mac is superior to a PC: You don't have all these .ugly .extensions .that .mean .nothing .to .normal .people.

Think about it: Filename extensions have no natural meaning to normal people. "OK, so you're telling me that .HTML means "Web page." Why don't you just call it ".Web page"? Why did you have to invent this cryptic four-letter abbreviation that shares no letters in common with the thing it actually means!?"

"Well, you see, HTML stands for HyperText Markup Language, which is the name some computer geeks made up to describe for the computer code used for producing Web pages."

It would be similar to the controls on your car labeled not by what they did but by the internally assigned part number that the control manipulates. The button for operating the windshield sprayer has the label SB5173-B92. Sure, your local auto mechanic may be able to explain, "That's because the car manufacturer doesn't build the side mirrors themselves; they're subcontracted to another company, which has a different numbering system for its parts ..."

"Wait, the side mirror is a powered component. I push the knob, and a motor turns the side mirror."

"Look, it's really quite simple once you learn it, and you really need to learn this stuff if you plan on using your car intelligently. Let me explain ..."

That's what file extensions sound like to normal people. They're a bunch of cryptic letters and numbers that have no inherent meaning, but you'd better get them right or everything stops working.

On the Mac, they just got rid of file extensions. You gave your document a name (which went into the filename), and the application that created it stored the file type information in a separate location. You didn't have to worry about the strange cryptic codes that computers use to keep track of file type information; all you did was give your document a name. Bliss.

On the other hand, somebody could create an application, give it an icon identical to that displayed for a bitmap image, and name the application "Anna Kournikova." Because the Mac doesn't show type information under the icon, a poor user would be fooled into thinking that they were opening a picture of Anna Kournikova, when in fact they were running a Trojan Horse. To know that you were actually running an application and not opening a document, you had to look over to the Kind column and see that it was identified as an application and not a MacPaint picture.

For some reason, this behavior was heralded as a clear sign of the Mac's superiority, while at the same time the identical behavior on the PC was heralded as proof of its inferiority. You just can't win.

Remember, the programmatic filename is really a multiplex of two different pieces of information: The user-assigned name and the file type. Explorer shows the user-assigned name next to the icon and the file type information under Type.

It might be argued that showing file extensions created the problem of malicious files named File.jpg.exe: When this programmatic filename is broken down into its user-assigned name of File.jpg and its type of Application, users who were trained by well-meaning geeks to interpret everything as a programmatic filename erroneously performed a second conversion and treated File.jpg as a programmatic filename instead of as a user-assigned name. If there had been no way to force extensions to be shown, nobody would try to perform this second conversion (because no such conversion would ever have been necessary), and the security issue would never have existed.

Raymond Chen's Web site, The Old New Thing, and identically titled book (Addison-Wesley, 2007) deal with Windows history and Win32 programming**.***