用 assoc 和 ftype 查看文件关联
两个被遗忘的 CMD 内置命令:扩展名 → 文件类型 → 可执行命令的两级映射。
运行 assoc .ext 查看文件类型名,再用 ftype <类型名> 查看启动命令;用 ftype 名称="命令" %1 %* 设置。
01命令
命令
$ assoc .py ; ftype Python.File02作用说明
关联分两级:assoc 把扩展名(如 .py)映射到类型名,ftype 把类型名映射到实际命令行,%1 代表文件本身,%* 代表附加参数。先 assoc 后 ftype 的组合是脚本注册自定义处理器的标准做法,如 assoc .log=MyLog 加 ftype MyLog=notepad.exe %1。这些信息存于 HKCR 注册表,ftype 本质上是注册表快捷方式。
03风险
!注意: 新版 Windows 常被每用户和界面层关联覆盖——“设置”应用中的选择优先于 assoc/ftype 的设置,修改后需实际验证。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- ASSOC - Windows CMD依据: SS64 explains assoc mapping extensions to file types and ftype mapping file types to commands, with examples of setting both.
- ftype | Microsoft Learn依据: Microsoft documents ftype displaying or modifying file type command strings used by assoc, including %1 %* argument substitution.
最后验证: 2026-09-17 · 分类: 开发者