Site navigation

Related links

Managing Files from the Command Line- Assoc and Ftype

Windows comes with several command-line tools for file management. The features and applications of Assoc and Ftype are discussed.
Before discussing the file management tools, I would like to quickly review some of the basic facts about how Windows manages files. (More details can be found at another site.) A very basic property of a file is its file type. Each file type has a set of specific actions that can be carried out with it or to it. The software that is assigned to do these actions with or to a particular file type is said to be "associated" with the file type. There may be several actions and different software may be involved for each particular action. This set of software constitutes the program associations for a given file type. The extension of a file is a tag that tells the computer what the file type is and what is to be done with the file when it is opened or double-clicked or otherwise invoked one way or the other. Microsoft also uses the word "associate" in connection with file extensions and refers to an extension being associated with a particular file type. All of this information is stored in the Registry and can be edited or changed in several ways. I have discussed methods that use the graphical interface on another site . Here we look at using the command line.

Manage file type and extension associations with the "assoc" command

This tool is very useful for managing the relationship or association between file extensions and file types. the syntax is assoc [.ext[=[fileType]]]If the plain command "assoc" is entered, you will get a list of what file types correspond to the extensions currently registered on the system. The list can be quite long so it is best to redirect to a file or to pipe to the "more" command so that one full screen at a time can be viewed assoc > list.txt     or     assoc | more If the only parameter is a file extension (including the leading period), the file type for that extension will be given. For example, to see what file type is associated with .txt , enter assoc .txtSince the names used for the various file types may not always be obvious, the above can be a useful type of command, In this case, the output would normally be .txt=txtfile. . To delete the file type association for the file name extension .xyz (use with care), enter assoc .xyz=Another use is to associate a given extension with a certain file type. As an example, to associate the extension .log with type txtfile, enter assoc .log=txtfile Note that more than one extension can be associated with a file type. For example, the file type "jpegfile" typically has both the extensions .jpg and .jpeg associated with it. Also note that it is possible to create your own file extensions and to associate them with a filetype.

For a Microsoft reference on assoc go here or to the Windows Help and Support Center. You can also enter.the commandassoc /?

Back to top

Manage file type and program associations with the "ftype" command

As previously mentioned, each file type has a set of operations and corresponding software associated with it. In particular, all active file types have an action named "Open" that is the default action. This is the action that is invoked when you double-click a file with an extension associated with the file type. There may also be other actions (listed in the Context Menu) but ftype deals with "Open". The "Open" action is defined by a string that includes the fully qualified path to the executable file that is to carry out the action and any parameters that must be passed to the executable. The syntax for ftype is ftype [fileType[=[openCommandString]]]

Entering the bare command "ftype" will list all of the current file types that have the open command strings defined and the corresponding command string. It can be quite a long list so it is best to redirect to a file or to pipe to the "more" command. Having the list can be convenient as a record of what programs are being used to open various files.

If a particular file type is specified, then the command string for that file type will be displayed. Using the text file type as an example, you would enter ftype txtfile This would produce the output txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1This shows that the executable file that opens text files is notepad.exe located in the folder \Windows\system32\ (The environment variable %SystemRoot% is used to indicate the Windows folder.) Note the presence of the placeholder %1. This is necessary because the full command for the open action requires the name of the file that is to be opened.and the placeholder stands for the file name. This command is useful when you want to see what program opens a particular file type.

If it were desired to change the openCommandString to use Wordpad instead of Notepad, the command (on one of my computers) would be ftype txtfile="G:\Program Files\Windows NT\Accessories\wordpad.exe" "%1" (The path for Wordpad will vary from one computer to the next. This example is for illustration only). Note the use of quotation marks to enclose a path with spaces in it. While changing program associations may be easier using the Windows Explorer Tools-Folder Options dialog (no typing required), the command line method can also be useful, especially in batch files.

Back to top