ftype

显示或修改在文件扩展名关联中使用的文件类型。 如果未使用赋值运算符(=),此命令将显示指定文件类型的当前打开命令字符串。 如果未使用参数,此命令将显示定义了打开命令字符串的文件类型。

Note

此命令仅在 cmd.exe 中受支持,不能从 PowerShell 获取。 尽管可以使用 cmd /c ftype 作为解决方法。

Syntax

ftype [<filetype>[=[<opencommandstring>]]]

Parameters

Parameter Description
<filetype> 指定要显示或更改的文件类型。
<opencommandstring> 指定打开指定文件类型的文件时要使用的 open 命令字符串。
/? 在命令提示符下显示帮助。

Remarks

The following table describes how ftype substitutes variables within an open command string:

Variable Replacement value
%0%1 获取替换为通过关联启动的文件名。
%* 获取所有参数。
%2%3,... 获取第一个参数(%2)、第二个参数(%3),等等。
%~<n> Gets all of the remaining parameters starting with the nth parameter, where n can be any number from 2 to 9.

Examples

若要显示已定义打开的命令字符串的当前文件类型,请键入:

ftype

To display the current open command string for the txtfile file type, type:

ftype txtfile

此命令生成类似于以下内容的输出:

txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1

To delete the open command string for a file type called example, type:

ftype example=

若要将.pl文件扩展名与 PerlScript 文件类型相关联,并启用 PerlScript 文件类型以运行PERL.EXE,请键入以下命令:

assoc .pl=PerlScript
ftype PerlScript=perl.exe %1 %*

若要在调用 Perl 脚本时无需键入.pl文件扩展名,请键入:

set PATHEXT=.pl;%PATHEXT%