- 1 year ago
Set Windows file type association for a specific file only
To set a file type association for a specific file only in Windows, you can use the ftype
and assoc
commands in the Command Prompt. Here's how to do it:
Open Command Prompt as an administrator:
Right-click on the Start menu, select "Command Prompt (Admin)" or "Windows PowerShell (Admin)."Check the current file type association for the specific file:
Run the following command to check the current file type association for the file extension you want to change. Replace<file_extension>
with the actual extension of the file you want to change:bashassoc .<file_extension>
Note down the file type association that is displayed (e.g., ".txt=txtfile").
Create a new file type association:
Run the following command to create a new file type association for the specific file:bashftype <file_type_association> "<path_to_program>" "%1"
Replace
<file_type_association>
with the file type association you want to create (e.g., ".txt=MyTextFile").
Replace<path_to_program>
with the full path to the program you want to use to open the file.
%1
is a placeholder that represents the full path of the file being opened.For example, to associate ".txt" files with Notepad, you can use the following command:
bashftype MyTextFile "C:\Windows\System32\Notepad.exe" "%1"
Update the file type association for the specific file:
Run the following command to update the file type association for the specific file:bashassoc .<file_extension>=<file_type_association>
Replace
<file_extension>
with the file extension of the specific file, and<file_type_association>
with the file type association you created in the previous step.For example, to associate ".txt" files with the "MyTextFile" file type association you created earlier, use the following command:
bashassoc .txt=MyTextFile
That's it! Now the specific file will have the custom file type association you set, while other files with the same extension will continue to use their default association.