File Types and File Extensions
One
of the fictions that Microsoft has tried to foist on the computer-using
public is that we live in a “document-centric” world. That is, that
people care only about the documents they create and not about the
applications they use to create those documents. This is pure hokum. The
reality is that applications are still too difficult to use and the
capability to share documents between applications is still too
problematic. In other words, you can’t create documents unless you learn
the ins and outs of an application, and you can’t share documents with
others unless you use compatible applications.
Unfortunately, we’re stuck
with Microsoft’s worship of the document and all the problems that this
worship creates. A good example is the hiding of file extensions. Here are just a few of the problems this
allegedly document-centric decision creates:
Document confusion | If
you have a folder with multiple documents that use the same primary
name, it’s often difficult to tell which file is which. For example, Figure 4.1 shows a folder with 18 different files named Project.
Windows Vista unrealistically expects users to tell files apart just by
examining their icons. To make matters worse, if the file is an image,
Vista shows a thumbnail of the image instead of an icon. The result is
that in Figure 1 it’s impossible to tell at a glance which image is a GIF, which is a JPEG, and so on. |
The inability to rename extensions | If you have a file named index.txt and you want to rename it to index.html, you can’t do it with file extensions turned off. If you try, you just end up with a file named index.html.txt. |
The inability to save a document | Similarly, with file extensions turned off, Windows |
under an extension of your choice | Vista
forces you to save a file using the default extension associated with
an application. For example, if you’re working in Notepad, every file
you save must have a txt extension. If
you create your own web pages, for example, you can’t rename these text
files with typical web page extensions such as .htm, .html, .asp, and so on. |
Tip
There is a way to
get around the inability to save a document under an extension of your
choice. In the Save As dialog box, use the Save as Type list to select
the All Files option, if it exists. You can then use the File Name text
box to type the filename with the extension you prefer to use.
You can overcome all
these problems by turning on file extensions. Why does the lack of file
extensions cause such a fuss? Because file extensions solely and completely determine the file type of a document. In other words, if Windows Vista sees that a file has a .txt extension, it concludes the file uses the Text Document file type. Similarly, a file with the extension .bmp uses the Bitmap Image file type.
Note
As a reminder, you
turn on file extensions by selecting Windows Explorer’s Organize, Folder
Options command, displaying the View tab, and deactivating the Hide
File Extensions for Known File Types check box.
The file type, in turn, determines the application that’s associated with the extension. If a file has a .txt extension,
Windows Vista associates that extension with Notepad, so the file will
always open in Notepad. Nothing else inherent in the file determines the
file type so, at least from the point of view of the user, the entire
Windows Vista file system rests on the shoulders of the humble file
extension.
This method of
determining file types is, no doubt, a poor design decision. For
example, there is some danger that a novice user could render a file
useless by imprudently renaming its extension. Interestingly, Microsoft
seems to have recognized this danger and programmed a subtle behavior
change into Vista: When file extensions are turned on and you activate
the Rename command (click the file and then press F2), Vista displays
the usual text box around the entire filename, but it selects only the file’s primary name (the part to the left of the dot), as shown in Figure 2. Pressing any character obliterates the primary name, but leaves the extension intact.
Despite the
drawbacks that come with file extensions, they lead to some powerful
methods for manipulating and controlling the Windows Vista file system.
File Types and the Registry
As you might expect, everything Windows Vista knows about file types is defined in the Registry. Open
the Registry Editor (press Windows Logo+R—or select Start, All Programs,
Accessories, run—type regedit, click OK, and enter your credentials) and examine the HKEY_CLASSES_ROOT key. Notice that it’s divided into two sections:
The first part of HKEY_CLASSES_ROOT consists of dozens of file extension subkeys (such as .bmp and .txt).
There are well over 400 such subkeys in a basic Windows Vista
installation, and there could easily be two or three times that number
on a system with many applications installed.
The second part of HKEY_CLASSES_ROOT
lists the various file types that are associated with the registered
extensions. When an extension is associated with a particular file type,
the extension is said to be registered with Windows Vista.
Note
HKEY_CLASSES_ROOT also stores information on ActiveX controls in its CLSID subkey. Many of these controls also have corresponding subkeys in the second half of HKEY_CLASSES_ROOT.
To see what this all means, take a look at Figure 3. Here, I’ve selected the .txt key, which has txtfile as its Default value.
That Default value is a pointer to the extension’s associated file type subkey in the second half of HKEY_CLASSES_ROOT.Figure 4 shows the txtfile subkey associated with the .txt extension. Here are some notes about this file type subkey:
The Default value is a description of the file type (Text Document, in this case).
The DefaultIcon subkey defines the icon that’s displayed with any file that uses this type.
The shell subkey determines the actions that can be performed with this file type. These actions vary depending on the file type, but Open and Print are common. The Open action determines the application that’s associated with the file type. For example, theOpen action for a Text Document file type is the following:
%SystemRoot%\system32\NOTEPAD.EXE %1
Note
The %1
at the end of the command is a placeholder that refers to the document
being opened (if any). If you double-click a file named memo.txt, for example, the %1 placeholder is replaced by memo.txt, which tells Windows to run Notepad and open that file.