如何创建一个可以选择文件并以该文件作为参数运行 DOS 命令的快捷方式?
我需要它能够向用户询问一个文件,然后在用户选择一个文件后,它将运行一个 CMD 命令,如“program.exe [选定的文件]”
I need this to be able to ask the user for a file, then after the user chooses one, it will run a CMD command like "program.exe [selected file]"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您要求一种方法让批处理脚本创建打开的文件对话框,我认为这是不可能的。您最好创建一个小程序来为您完成此操作。
If you're asking for a way to have a batch script create an open file dialog, I don't believe that's possible. You're better off creating a small program that will do this for you.
可能有办法,但我不知道。我将介绍一些替代方案。
GUI 主要通过将命令附加到文件来工作,而不是相反。您可以使用文件扩展名来做到这一点。您可以使用发送到来做到这一点。
文件扩展名允许将命令(例如perl)与文件扩展名(例如.pl)关联起来。使用“assoc”和“ftype”,可以将名称与扩展名关联起来,并将命令与该名称关联起来。
我现在不在我的 Windows 机器上,所以我不能给你确切的用法。在提示符处输入“help assoc”和“help ftype”以供使用。在命令中使用“%1”(包含引号)来指示所单击的文件的名称应出现在命令中的位置。
每当您双击具有该扩展名的文件时,它将使用您的命令启动。
或者,您可以使用“发送至”。您的个人资料中的某个位置有一个名为“发送到”的目录。 (只需搜索即可找到它。)在其中放置应用程序的快捷方式。要使用快捷方式,请右键单击要打开的文件,选择“发送到”,然后选择应用程序。
There might be a way, but I don't know it. I'm going to cover some alternatives.
GUIs work mostly by attaching commands to files, not the other way around. You can do that using file extensions. You can do that using Send To.
File extensions permit the association of an command (e.g. perl) with a file extension (e.g. .pl) Using "assoc" and "ftype", one associates the name to an extension, and a command to that name.
I'm not at my Windows machine at the moment, so I can't give you the exact usage. Type "help assoc" and "help ftype" at the prompt for usage. Use "%1" (quote included) in the command to indicate where the name of the clicked file should appear in the command.
Whenever you double-click on a file with that extension, it will be launched in with your command.
Alternatively, you can use "Send To". Somewhere in your profile is a directory named "Send To". (Just do a search to find it.) Put a shortcut to the application in there. To use the shortcut, right-click on the file you want to open, choose Send To, choose the application.
查看
cmd
命令(Windows 上 DOS 命令行的现代版本),它可以递归地调用自身。通过在命令提示符下键入cmd /?
可以使用命令行选项。Check out the
cmd
command (the modern version of the DOS command line on Windows), which can invoke itself recursively. The command-line options are available by typingcmd /?
at a command prompt.