Windows:建立与​​批处理文件的文件关联 [英] Windows: establish file association to batch file

查看:140
本文介绍了Windows:建立与​​批处理文件的文件关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义文件扩展名,该文件扩展名将与批处理脚本关联. 我用过

I created a custom file extension I would associate to a batch script. I used

ASSOC .myext=MY.FILETYPE
FTYPE MY.FILETYPE=cmd /c "C:\Path\of\my\batch.bat" %1 %*

到目前为止,批处理文件"C:\ Path \ of \ my \ batch.bat"是一个简单的单行代码.

by now the batch file "C:\Path\of\my\batch.bat" is a simple one-liner

echo %1

大致可行:双击.myext文件会弹出一个cmd shell,回显文件路径.
但是,当.myext文件位于包含空格的路径中时,就会出现问题:回显的文件路径被截断到该空格.
在FTYPE语句中双引号%1似乎不起作用.

And roughly works: double clicking a .myext file pops up a cmd shell echoing the file path.
But a problem arises when the .myext file is in a path containing spaces: the echoed filepath is truncated to the space.
Double quoting the %1 in the FTYPE statement seems not to work.

FTYPE MY.FILETYPE=cmd /c "C:\Path\of\my\batch.bat" "%1" %*

推荐答案

双引号%1是正确的,但由于命令和至少一个参数包含引号的cmd.exe包含错误,因此失败. 因此,您需要通过插入CALL来使命令不带引号.

Double quoting %1 is correct, but it fails as cmd.exe contains a bug when the command and at least one parameter contains quotes.
So you need to make the command without quotes by inserting CALL.

FTYPE MY.FILETYPE=cmd /c call "C:\Path\of\my\batch.bat" "%1" %*

这篇关于Windows:建立与​​批处理文件的文件关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆