仅按名称打开文件,无扩展名

时间:2012-06-01 16:45:46

标签: command-line batch-file cmd

如何通过仅提供文件名,无扩展名来打开.bat中的任何类型的文件? 我想让windows决定要使用的应用程序。

示例:

%SystemRoot%\ explorer.exe E:\ SomeFolder \

%SystemRoot%\ explorer.exe E:\ SomeFolder \ file1

1 个答案:

答案 0 :(得分:1)

使用START命令:

start "Any title" E:\SomeFolder\
start "Any title" E:\SomeFolder\file1

摘自开始帮助:

If Command Extensions are enabled, external command invocation
through the command line or the START command changes as follows:

non-executable files may be invoked through their file association just
    by typing the name of the file as a command.  (e.g.  WORD.DOC would
    launch the application associated with the .DOC file extension).
    See the ASSOC and FTYPE commands for how to create these
    associations from within a command script.

When searching for an executable, if there is no match on any extension,
then looks to see if the name matches a directory name.  If it does, the
START command launches the Explorer on that path.  If done from the
command line, it is the equivalent to doing a CD /D to that path.

请注意,之前的描述意味着纯文件名也必须执行正确的应用程序,没有START命令。要获取具有给定名称的第一个文件:

for %%f in (name.*) do set "filename=%%f" & goto continue
:continue

...并执行它:

%filename%

PS - 请注意,您希望“让Windows决定要使用的应用程序”,但在您的示例中,您明确选择%SystemRoot%\explorer.exe作为要使用的应用程序。所以?