assoc / ftype - File Associations
When you double-click a .txt file in File Explorer and Notepad opens, that is because the extension is associated with an app.
assoc and ftype are commands for viewing and changing these associations from Command Prompt.
The Difference Between assoc and ftype
A Windows file association works in two steps.
- Extension → file type (handled by
assoc) - File type → command to run (handled by
ftype)
| Command | What it handles | Example |
|---|---|---|
assoc | Extension to file type | .txt → txtfile |
ftype | File type to the command that opens it | txtfile → command that runs Notepad |
When you open a .txt file, Windows uses the assoc information to find the type “txtfile”, then uses the ftype information to decide which program to launch.
assoc and ftype are built into cmd.exe. PowerShell has no cmdlets with these names, so from PowerShell run them with cmd /c, as in cmd /c assoc .txt.
How to Use assoc
Viewing an Association
assoc [.extension[=[filetype]]]
If you specify an extension, the file type for that extension is displayed.
assoc .txt
If you run it with no arguments, all registered associations are listed. The list is long, so combining it with findstr or more is handy.
assoc | findstr /i "\.htm"

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
For how to use pipes, see
.File type names depend on the installed apps. For example, .html may be named htmlfile, ChromeHTML, MSEdgeHTM, and so on, depending on the browser.
Changing or Deleting an Association
Specify a file type on the right side of = to set the mapping for an extension.
assoc .log=txtfile
Leave the right side of = empty to delete the association for that extension.
assoc .log=
Changes to associations are written to HKEY_LOCAL_MACHINE\Software\Classes in the registry. In a regular Command Prompt you will see “Access is denied”, so run it as administrator by following
How to Use ftype
Viewing the Command for a File Type
ftype [filetype[=[command string]]]
If you specify a file type, the command that is run to open that kind of file is displayed.
ftype txtfile
%1 is replaced with the path of the file being opened. Depending on the environment, %L (the file path) or %* (the remaining arguments) may also be used. Running ftype with no arguments lists all file types and their commands.
Changing the Command
ftype txtfile="C:\Program Files\MyEditor\editor.exe" "%1"
If the path contains spaces, enclose the executable’s path in ". It is also standard to write "%1" in quotes so that file names containing spaces work.
When you write %1 inside a batch file, double the percent sign as %%1. Otherwise it is replaced by the batch file’s own first argument. See
Like assoc, ftype requires administrator rights to make changes.
Practical Examples
Registering a New Extension and Opening It with a Specific App
This example creates a new .myd extension and opens it with your own app. Run it as administrator.
@echo off
rem Register .myd as the MyDataFile type
assoc .myd=MyDataFile
rem Set how MyDataFile is opened
ftype MyDataFile="C:\Tools\mydata.exe" "%%1"
To remove it later, run assoc .myd= and ftype MyDataFile=.
Finding Out Which App Handles an Extension
Look up the type with assoc, then look up the command with ftype.
assoc .py
ftype Python.File
On the second line, specify the file type shown by the first line (Python.File here).
Searching the ftype List for a Specific App
ftype | findstr /i "notepad"
When Your Changes Don’t Take Effect
Even after you change assoc or ftype, the app that opens on double-click may not change.
Since Windows Vista, the app a user picks with “Always use this app” is stored per user in the registry (HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.extension\UserChoice). This setting takes priority over assoc and ftype.
assoc/ftyperewrite the machine-wide default association (ProgID). If the user’s chosen default app (UserChoice) points to a different ProgID, it takes priority and your change has no effect.- To change the default app, use “Default apps” under “Apps” in Windows Settings.
- What
assoc/ftypedisplay is the content ofHKEY_CLASSES_ROOT; the default app the user chose in Settings (UserChoice) is not reflected.
You can check which app actually opens a file with start "" filename. start opens files according to the association. See
Summary
assochandles “extension → file type”, andftypehandles “file type → command to open it”- Run with no arguments for a list; use
assoc .extensionorftype typeto check one entry - Use
=to set, and leave the right side of=empty to delete (assoc .log=/ftype type=) - Changes require administrator rights, and
%1in a batch file must be written%%1 - The user’s chosen default app takes priority, so if changes don’t apply, check the “Default apps” settings