[英]How do I access the original file name that is associated a batch file
I have created my own file extension and associated that file extension with a batch file, that is simply suppose to call a ruby script. 我创建了自己的文件扩展名,并将该文件扩展名与批处理文件相关联,这只是假设要调用ruby脚本。 So the ruby script will execute and modify the original file (Test.jim).
因此,ruby脚本将执行并修改原始文件(Test.jim)。 However I need to pass the name of the original file to the ruby script so it can access it.
但是我需要将原始文件的名称传递给ruby脚本,以便它可以访问它。 My batch file is simply
我的批处理文件很简单
ruby batrun.rb %0
However this passes the name/path of the batch file not the original file with my file extension. 但是,这会传递批处理文件的名称/路径,而不是带有我的文件扩展名的原始文件。 How can I pass this through the batch file.
我如何通过批处理文件。
*EDIT *编辑
As asked for this is how I associate my file extension with the batch file 根据要求,这是我如何将文件扩展名与批处理文件关联
Ftype jimfile="C:\Users\Server\Desktop\File Extension\Jimbat.bat" "%1"
Assoc .jim=jimfile
I just put that in a batch file and then ran it. 我只是将其放入批处理文件中,然后运行它。
If anyone in interested I figure out how to fix it. 如果有兴趣的人,我会找出解决方法。 For some reason running the association through a batch file will NOT allow for the addition of parameters.
由于某些原因,通过批处理文件运行关联将不允许添加参数。 I have absolutely no idea why, but simply typing the exact same thing
我完全不知道为什么,但只需输入完全相同的内容
ftype jimfile="C:\Users\Server\Desktop\FileExtension\Jimbat.bat" %1
into a cmd with administrative access will work perfectly 进入具有管理访问权限的cmd会完美
Just a clarification the answer would be use these command at command prompt: 只是为了澄清答案,将在命令提示符处使用以下命令:
Assoc .jim=jimfile Ftype jimfile="C:\\Users\\Server\\Desktop\\File Extension\\Jimbat.bat" "%1" %* set PATHEXT=.jim;%PATHEXT%
but in a batch file: 但在批处理文件中:
Assoc .jim=jimfile Ftype jimfile="C:\\Users\\Server\\Desktop\\File Extension\\Jimbat.bat" "%%1" %%* set PATHEXT=.jim;%PATHEXT%
jimbat.bat contains: jimbat.bat包含:
echo ruby batrun.rb %* ruby batrun.rb %*
Notes: 笔记:
If you type test.jim abc
the command will be as if you typed ruby batrun.rb "C:\\Users\\Server\\Desktop\\File Extension\\test.jim" abc
a quoted full path to test.jim
(assuming same directory). 如果键入
test.jim abc
该命令将与键入ruby batrun.rb "C:\\Users\\Server\\Desktop\\File Extension\\test.jim" abc
带引号的test.jim
完整路径(假定目录相同) 。 Your last comments indicate you are now using double quotes. 您的最新评论表明您正在使用双引号。 Using double quotes it typical when using batch file scripts with extension associations.
当使用具有扩展名关联的批处理文件脚本时,通常使用双引号。 Look at
ftype
output you will see many programs do not use double quotes because of the way the handle command line arguments. 查看
ftype
输出,您将看到由于句柄命令行参数的方式,许多程序不使用双引号。
If you had wanted ruby batrun.rb C:\\Users\\Server\\Desktop\\File Extension\\test.jim abc
the ftype
would omit double quotes as indicated in ftype /h
. 如果您想要
ruby batrun.rb C:\\Users\\Server\\Desktop\\File Extension\\test.jim abc
则ftype
将省略双引号,如ftype /h
。 You only need %*
to allow for more than one argument otherwise %1
is sufficient. 您只需要
%*
即可允许多个参数,否则%1
就足够了。
assoc
, ftype
goes to registry and applies to windows globally. assoc
, ftype
进入注册表并全局应用于Windows。 I noticed when testing you can clear assoc
from cmd.exe but ftype
can only by removed using registry tool not ftype
command. 我注意到测试时,可以清除时
assoc
从cmd.exe的,但ftype
只可以使用注册表工具不会被删除ftype
命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.