Mastering File Types
in this chapter
Understanding File Types
Working with Existing File Types
Creating a New File Type
Associating Two or More Extensions with a Single File Type
Customizing the New Menu
Customizing Windows XP's Open With List
Amazingly, a long list of useful and powerful Windows XP features are either ignored or given short shrift in the official Microsoft documentation. Whether it's the Windows XP startup options, group policies, or the Registry (to name just three that I discuss in this book), Microsoft prefers that curious users figure these things out for themselves (with, of course, the help of their favorite computer book authors).
The subject of this chapter is a prime example. The idea of the file type can be described, without hyperbole, as the very foundation of the Windows XP file system. Not only does Microsoft offer scant documentation and tools for working with file types, but they also seem to have gone out of their way to hide the whole file type concept. As usual, the reason is to block out this aspect of Windows XP's innards from the sensitive eyes of the novice user. Ironically, however, this just creates a whole new set of problems for beginners and more hassles for experienced users.
This chapter brings file types out into the open. You'll learn the basics of file types and then see a number of powerful techniques for using file types to take charge of the Windows XP file system.
Understanding File Types
To get the most out of this chapter, you need to understand some background about what a file type is and how Windows XP determines and works with file types. The next couple of sections tell you everything you need to know to get you through the rest of the chapter.
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. As you learned in Chapter 2, "Exploring Expert File and Folder Techniques," Windows XP turns off file extensions by default. Here are just a few of the problems this allegedly document-centric decision creates:
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 3.1 shows a folder with 15 different files named Project. Windows XP unrealistically expects users to tell files apart just by examining their icons.
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 XP forces under an extension of your choice 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.
Figure 3.1 With file extensions turned off, it’s often difficult to tell one file from another.
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 XP sees that a file has a .txt extension, it knows the file uses the Text Document file type. Similarly, a file with the extension .bmp uses the Bitmap Image file type.
The file type, in turn, determines the application that’s associated with the extension. If a file has a .txt extension, Windows XP 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 XP 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.) However, it also leads to some powerful methods for manipulating and controlling the Windows XP file system, as you’ll see in this chapter.
File Types and the Registry
As you might expect, everything Windows XP knows about file types is defined in the Registry. (See Chapter 8, "Getting to Know the Windows XP Registry," for details on understanding and using the Registry.) You use the Registry to work with file types throughout this chapter, so let’s see how things work. Open the Registry Editor 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 more than 300 such subkeys in a basic Windows XP 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 XP.
To see what this all means, take a look at Figure 3.2. Here, I’ve highlighted the .txt key, which has txtfile as its Default value.
Figure 3.2 The first part of the HKEY_CLASSES_ROOT key contains subkeys for all the registered file extensions.
That Default value is a pointer to the extension’s associated file type subkey in the second half of HKEY_CLASSES_ROOT. Figure 3.3shows 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, the Open action for a Text Document file type is the following:
Figure 3.3 The second part of HKEY_CLASSES_ROOT contains the file type data associated with each extension.
The File Types Tab: A Front-End for HKEY_CLASSES_ROOT
For much of the work you do in this chapter, you won’t have to deal with the Registry’s HKEY_CLASSES_ROOT key directly. Instead, Windows XP offers a dialog box tab that acts as a front-end for this key. Follow these steps to display this tab:
In Windows Explorer, select Tools, Folder Options to display the Folder Options dialog box.
Select the File Types tab.
Figure 3.4 shows the File Types tab. The Registered File Types list shows all the file types known to Windows XP, as well as their extensions. When you select a file type, the Opens With line in the Details area shows you the icon and name of the program associated with the file type.