workstation
Reprint

    File Types

    I recently ran an article on how to make your own Actions in Context Menus, but I grossly neglected the basics of File Types: associating extensions with File Types, and defining File Types.

    When you launch a file in Explorer by [single- or double-] clicking on it, Explorer checks the Registry hive CLASSES_ROOT to find the file extension, then it's associated File Type, which defines the default Action (command to run, usually the application to open) to take when that file type is opened.

    The purview of the previous article was defining other options available in the context menu of an object (file) when you right-click on it from Explorer. This article will deal with default Actions (the ones that are bold in the context menus).

    "Auto Files"

    If something in that launch process fails (if either the file's extension isn't registered, or it's File Type doesn't have an associated application), you're presented with a dialog asking you to pick an application in which to open the file. If you pick an application, and don't uncheck the box saying "Always use this program to open this file" (it's checked by default), you'll get:

    1. that file's extension registered in CLASSES_ROOT, and associated with

    2. an "auto_file" file type, which will read something like "{ext}_auto_file", and which contains

    3. the name and path to the program you chose to associate the extension with.

    The problem with these "auto files" is that it's hard to get rid of them, because they're not obvious: they don't show up in the "File Types" dialog of Explorer\View\Folder Options.

    File Types Dialog Problems

    I never liked the File Types dialog, for various reasons:

    1. Not all File Types show up (these "auto files" in particular)

    2. File Types that are easy to misconfigure, such as exe and Folder, do show up

    3. You can't add an extension to a current File Type

    Should I mention that the thing is clunky (slow), and that it's hard to edit commands in the dialog for File Type Actions?

    Did you balk at #2? Read the newsgroups: users are deleting (or otherwise manipulating) "system" and "shell" file types all over the place! These issues are FAQs, for crying out loud! People do this stuff!

    And why shouldn't they? Users aren't supposed to mess with "The Registry", but here's a nice little dialog available immediately from Explorer to any computer User which can render your system seemingly inoperable (or "intolerable" at least).

    And if you've ever tried to add an extension to an existing file type from this dialog, you've probably ended up just making up a whole new file type just for that extension, then associating the type with whatever application you needed.

    Back to the Command Line

    For viewing all your File Types, I suggest looking at the CLASSES_ROOT hive in the Registry just to see what's there. You can search key names (View\Find Key...) for "auto_file" (no options selected) to turn up any "auto file" types (in case you want to clean them up).

    There are two command line commands related to File Types that are extremely useful, and should be in everyone's vocabulary: ASSOC and FTYPE.

    With ASSOC, you can associate an extension with a file type, view the file type the extension is associated with, or delete the extension's association altogether, as follows:

      ASSOC .txt = txtfile
      associates TXT files with the file type "txtfile"

      ASSOC .txt
      displays the file type with which TXT is associated

      ASSOC .txt=
      deletes the TXT association (so it's not associated with any file type)

    FTYPE is very similar, except it works with File Types instead of extensions:

      FTYPE txtfile = c:\utils\editor.exe "%1"
      opens txtfile files with this particular editor program

      FTYPE txtfile
      displays the default command associated with txtfile

      FTYPE txtfile=
      deletes the txtfile file type

    Note that FTYPE works only with the default Action associated with the File Type. If you want to get fancier, you have to use the File Types dialog and/or edit the Registry.

    And as easy as it is to create a new filetype, it would probably be better in most cases to work with existing file types recognized almost as "standard", like "jpegfile", "giffile", and "txtfile" (isn't that brilliant! take the extension, add "file"... beautiful naming convention!).

    Hence, to associate your TXT files with a new editor, don't try to make a new file type called "mytxtfiles". Instead, discover the file type already in use (in this case, use ASSOC .txt, which would return "txtfile"), then FTYPE that file type to open your new text editor (FTYPE txtfile = c:\utils\editor.exe "%1"). Now all extensions associated with "txtfile" will open your new text editor.

    Send To Folder

    While messing with File Types can save you a lot of headache, you might not want to associate every file extension that comes your way (like the .me in Read.me files). And then there's the issue of files without extensions at all (often "readme" files, also).

    If you find yourself associating a bunch of file extensions with a certain application (usually your text editor, especially if it's a capable text editor), you might find yourself well rewarded by putting a shortcut to your often-used applications in your Send To folder, located in your WINNT\Profiles\{User} folder. That way, right-clicking any file will give you the option to send that file to your editor (or any other application you have in Send To).

    Specific File Type Fixes

    As I mentioned above, some of these are FAQs: we play around with File Types, and accidentally delete or otherwise corrupt one so the shell doesn't function as it should. These are the most common mess-ups (or the most messy mess-ups!), and how to fix them:

    Batch Files:

      ftype batfile="%1" %*
      assoc .bat=batfile

    Executables:

      ftype exefile="%1" %*
      assoc .exe=exefile

    Notice that the batch files (as well as cmd files) and executables just run the file name, but with %* as a parameter. That means that NT launches the file, and the "percent-asterisk" allows the command to have any number of parameters to boot.

    You do this if you want to something like REXX to run "natively" from NT, so you can enter the rexx command, and any number of REXX command-specific parameters, directly from NT.

    Folders:

      ftype folder=%SystemRoot%\Explorer.exe /idlist,%I,%L

      assoc folder=folder