0

我在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把它当作文件

回答

2

使用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. 
+0

工程就像一个魅力!谢谢。 – user837208 2012-04-05 10:32:36