转义“)”在Windows批处理中“for”命令
我需要迭代文件中的行。以下命令不起作用:
set filename=c:\program files (x86)\somewhere
...
for /f "delims==" %%i in (%filename%) do echo %%i
因为文件名中存在“)”。错误:
\somewhere) was unexpected at this time.
通过“^”转义在这里不起作用,因为我需要使用变量而不是内联文件名。如何解决这个问题?
I need to iterate lines in a file. Following command doesn't work:
set filename=c:\program files (x86)\somewhere
...
for /f "delims==" %%i in (%filename%) do echo %%i
because of ")" in the filename. Error:
\somewhere) was unexpected at this time.
Escaping by "^" doesn't work here because I need to use an variable instead of inline filename. How to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将文件名放在双引号中,同时添加
usebackq
选项:从
FOR /?
的输出中:Put the filename in double quotes, but also add the
usebackq
option:From the output of
FOR /?
:USEBACKQ 允许您对带有空格的路径使用双引号
USEBACKQ allows you to use double quotes for paths with spaces