File Associations – What they are & How to Change them
(ASSOC Command, CMD)
What We'll Learn:
This short guide is all about extension associations and file types.
- We are going to learn, what file types and extension associations are.
- How we can view the associations between file types and extensions using the windows command line.
- And how to change the association of certain file type with an extension from the command line.
And much more.
What are File Associations in Windows?
Windows associates every extension with a certain file type so that it knows the type of data contained within that file, and thus how to execute or open it.
For example, windows by referencing the extension association of a .png file knows that it’s an image and opens it with the appropriate application.
File types are names that windows gives to every file of a certain type, for example text files use the txtfile file type.
One file type can also be associated with many extensions. For example, both .7z and .zip extensions are associated with the 7-Zip file type.
On the other hand, an extension can only be associated with one file type.
View Associations Using The Assoc Command
Open your command line and use the assoc command without any parameters to view every extension as well as its file type association.
Every extension and file type in your system will immediately show up.
Note the names of the file types that appear, are a bit different than what they are on the GUI.
That’s because windows displays the file type names that are more easily understood to its users rather than those that it uses internally. For example, what you usually see as “Text Document” appears as “txtfile”.
You can view how the name of a file type is usually displayed us simply by typing its name after the assoc command.
And as you can see the “txtfile” file type is displayed as “text document”.
Using the assoc command we can view and change the file type association of a specific extension simply by typing the assoc command followed by the name of an extension.
The file type of the .txt extension will immediately show up.
Change Associations Using The Command Line
By changing the extension association of a file type, we can determine which application should be used to open it.
For example, lets make every file with a .txt extension open with Microsoft Word.
First, we must find out what file type word documents use. To do so let’s view the association of an existing extension that opens Microsoft word, such as .docx.
Let’s verify that this is our file type, by typing its name after the assoc command.
And as you can see this file type indeed opens Microsoft Word documents. As expected.
Now that we know what file type to use let’s associate it with the .txt extension.
To change the file type of an extension simply type the assoc command followed by your extension and make it equal to the file type of your choice.
Windows will now treat .txt files as word documents and open them with Microsoft word.
If you get an “Access is denied error” You need to run the command in a command prompt with administrator privileges.
Note that you cannot assign any association to any file type. That’s because the application of your choice might not know how to handle the data contained within your file.
For example, if you were to make every .rar file open as a text document, your text editor would not have been able to read and understand your file.
That’s why its important that are incredibly careful when changing extension associations, the wrong command can easily make files of a certain extension or file type unopenable.
Finally, you can associate a file type to only extensions that do not have any existing associations. For example, to make windows open every file with an unrecognized extension as a text document type the following:
Any file that has an unrecognized extension will now be opened as a text document.
Assoc Command Examples:
Display every association between the file types and extensions in your computer.
Display the extension association of the txtfile file type.
Display the file type associated with the .txt extension.
Associate every .txt extension with the word document file type. This will make every text file open with Microsoft word.
Associate every extension that does not have any association with the txtfile file type. This will make every unrecognized extension in your computer open as a text file.
Assoc Help Output:
Displays or modifies file extension associations
.ext Specifies the file extension to associate the file type with fileType Specifies the file type to associate with the file extension
Type ASSOC without parameters to display the current file associations.
If ASSOC is invoked with just a file extension, it displays the current file association for that file extension.
Specify nothing for the file type and the command will delete the association for the file extension.
- File associations are the references between extensions, and file types, and they are used so that windows knows how to interact with files.
- One file type can be associated with many extensions, but an extension can only be associated with one file type.
- Use the assoc command to change the extension association of a file type and determine which application should be used to open it.
You now know what file extension associations and file types are and how you can use them.
If you liked this short guide take a look at a few of our other posts related to the windows command line, or if you really liked it consider enrolling in our video course where you will learn the ins and outs of the Windows command Line.