如何在Windows命令行中转义?
问题描述:
我在c:\Program Files
目录中有一个文件tmp.txt
如何在Windows命令行中转义?
对于tmp.txt中的每一行,我想执行一条命令。
我想使用命令提示符for
循环,但它无法找到tmp.txt。请注意,我必须在c:\Program Files
目录中运行此命令。
这里是我正在尝试:
C:\>for /F %i in ("c:\Program Files\tmp.txt") do echo "%i"
输出为:
C:\>echo "c:\Program"
"c:\Program"
这意味着for
正在考虑"c:\Program"
作为参数,并将其传递给do
如果我把文件在c:\
,并运行for
循环为 -
C:\>for /F %i in (c:\tmp.txt) do echo "%i"
它工作得很好
所以我的问题是 - 如何传递完整路径for
循环,使for
把它当作文件
答
使用usebackq
选项for /f
:
for /f "usebackq" %i in (...)
这会更改各种引用字符的语义,如同帮助状态一样:
usebackq - specifies that the new semantics are in force,
where a back quoted string is executed as a
command and a single quoted string is a
literal string command and allows the use of
double quotes to quote file names in
file-set.
工程就像一个魅力!谢谢。 – user837208 2012-04-05 10:32:36