Windows x64 和 Windows “路径中的括号”批处理文件问题
Windows x64 版本包含以括号命名的文件夹,如“\Program Files (x86)”,这会破坏我使用的批处理文件。问题行的示例:
对于 (%path%) 中的 %%c,如果存在“%%c\xyz.exe”,请设置 xyz=OK
,即当它到达“(x86)”中的“)”时,它会输出一个错误消息并退出...
有关如何解决此问题的任何想法吗? 这是一个相当大的批处理文件,并且 atm 我没有时间用更好的语言重写它......
非常感谢:)
Windows x64 versions contain folders named with parenthesis like "\Program Files (x86)" and this breaks a batch file I use. An example of a problem line:
for %%c in (%path%) do if exist "%%c\xyz.exe" set xyz=OK
i.e. when it reaches ")" in "(x86)" it puts out an error message and exits...
Any ideas on how to fix this?
This is a rather large batch file, and atm I don't have the time to rewrite it in a better language...
Many thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不直接回答您的问题,但如果您尝试执行我认为您正在尝试的操作(即确保路径中存在文件),您可以在批处理文件中使用类似以下内容的内容。
Doesn't directly answer your question, but if you are trying to do what I thinking you are trying (which is make sure a file exists in the path) you can use something like the following in a batch file.
通常引用应该有效,但在这种情况下,您想要迭代由
;
分隔的所有元素。但是您可以将
;
替换为" "
组合,这样括号就会被引用,并且您可以迭代元素。示例:
path=C:\temp;C:\windows;C:\Program Files (x86)
for 循环将搜索
"C:\temp" "C:\windows" "C:\Program Files (x86)"
作为代码,它看起来像
Normally quoting should work, but in this case you want to iterate over all elements seperated by
;
.But you can replace the
;
to a" "
combination, so the brackets are quoted and you can iterate over the elements.sample:
path=C:\temp;C:\windows;C:\Program Files (x86)
The for-loop will search in
"C:\temp" "C:\windows" "C:\Program Files (x86)"
As code it looks like
为此,您可以使用文件夹的短名称。这就是你的做法。
在 Windows 中打开命令提示符。
转到 C 驱动器(或包含程序文件夹的驱动器)
键入以下内容,
这将返回所有文件夹的缩写形式。
您现在会注意到“\Program Files (x86)”将表示为“PROGRA~2”(或等效的短名称)。
这是我在创建批处理脚本时用来防止出现任何错误的方法。
有关更多选项,请参见此处。
http://www.computerhope.com/dirhlp.htm
“dir /”的解释x”
“这显示为非 8dot3 文件名生成的短名称。格式为 /N,在长名称之前插入短名称。如果不存在短名称,则在其位置显示空白。”
You can use the short names of the folder for this purpose. This is how you do it.
Open command promt in Windows.
Go to C drive (or the drive in which you have the Program Folder)
Type the following and
This will return the short forms of all folders.
You will notice now that "\Program Files (x86)" will be represented as "PROGRA~2" (or an equivalent short name).
This is what I use to prevent any errors while creating Batch scripts.
For more options see here.
http://www.computerhope.com/dirhlp.htm
Exlpanation for "dir /x"
"This displays the short names generated for non-8dot3 file names. The format is that of /N with the short name inserted before the long name. If no short name is present, blanks are displayed in its place."