如何通过仅提供文件名而不提供扩展名来打开 .bat 中的任何类型的文件?我想让 Windows 决定要使用的应用程序。
例子:
%SystemRoot%\explorer.exe E:\SomeFolder\
%SystemRoot%\explorer.exe E:\SomeFolder\file1
如何通过仅提供文件名而不提供扩展名来打开 .bat 中的任何类型的文件?我想让 Windows 决定要使用的应用程序。
例子:
%SystemRoot%\explorer.exe E:\SomeFolder\
%SystemRoot%\explorer.exe E:\SomeFolder\file1
使用 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
了要使用的应用程序。所以?