简体   繁体   English

如何访问与批处理文件关联的原始文件名

[英]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 abcftype将省略双引号,如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. assocftype进入注册表并全局应用于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.

相关问题 如何在Windows批处理中将文件通过管道传输到加密的,受密码保护的zip文件中,然后删除原始文件? - How do I pipe a file into an encrypted, password protected zip file, then delete the original file, in Windows batch? 如何在标签中获取正在运行的批处理文件的名称? - How do I get the name of the running batch file while in a label? 通过双击关联文件打开c ++程序。 如何获得文件名? - Opening c++ program by double clicking associated file. How do I get the file name? 在批处理文件中,如何从文件路径中分离文件名和文件扩展名? - In a batch file, how do I separate a file name and a file extention from a file path? 在批处理文件中,如何从文件路径获取文件名? - In a batch file, how do I get a file name from a file path? 如何使用批处理文件创建批处理文件? - How do I create a batch file with a batch file? 如何将批处理文件的结果输出到与输入文件同名的文件夹中? - How do I output the results of a batch file into a folder with the same name as the input file? 如何从文件名的一部分创建批处理文件夹,将文件移动到具有修改名称的文件夹中? - How do I create batch folder from part of file name, move files into folder with a modified name? 如何将文件名保存到Windows批处理文件中的变量中? - How do you save a file name into a variable in a windows batch file? 如何在批处理程序中打开文件? - How do i open a file in a program with batch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM