为什么不延迟扩展在for命令中作为参数工作 [英] Why doesn't delayed expansion work as parameter in a for command
本文介绍了为什么不延迟扩展在for命令中作为参数工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为变量中提供的每个路径执行一些for循环. echo !temp!
可以正常工作,但是下面的for命令将不起作用:
I want to execute some for loops for every path provided in a variable. The echo !temp!
works just fine, however the for commands below it won't work:
@echo off
setlocal enabledelayedexpansion
set paths=(C:\test C:\test2)
for %%p in %paths% do (
set temp=%%p
echo !temp!
for /r !temp! %%f in (*.h) do (echo %%f)
for /r !temp! %%g in (*.h *.cpp) do (echo %%g)
)
推荐答案
在所有 for
命令中语法模式:
In all for
commands syntax patterns:
FOR %%parameter IN (set) DO command
FOR /R [[drive:]path] %%parameter IN (set) DO command
FOR /D %%parameter IN (folder_set) DO command
FOR /L %%parameter IN (start,step,end) DO command
FOR /F ["options"] %%parameter IN (filenameset) DO command
FOR /F ["options"] %%parameter IN ("Text string to process") DO command
FOR /F ["options"] %%parameter IN ('command to process') DO command
在第一个分析阶段中,%%parameter
之前的所有文本都应该是已知的.阅读 Windows命令解释器(CMD.EXE)如何解析脚本?.
all text preceding %%parameter
should be known in the first parsing phase. Read How does the Windows Command Interpreter (CMD.EXE) parse scripts?.
但是,下一个脚本应该可以正常工作
However, next script should work as expected
@ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
set "paths=(C:\test C:\test2)"
for %%p in %paths% do (
set "temp=%%~p"
echo !temp!
call :doit
)
rem skip procedure
goto :domore
:doit
for /r "%temp%" %%f in (*.h) do (echo %%f)
for /r "%temp%" %%g in (*.h *.cpp) do (echo %%g)
goto :eof
:domore
这篇关于为什么不延迟扩展在for命令中作为参数工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文