嵌套批次循环 [英] Nested batch for loops
本文介绍了嵌套批次循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下嵌套for循环使我疯了(在Windows 7):
The following nested for-loop drives me mad (on Windows 7):
@echo off
SetLocal EnableDelayedExpansion
set TESTDIRS=fast mid slow
set TD=src\test\resources\testsuite
for %%d in (%TESTDIRS%) do (
set CTD=%TD%\%%d
echo CTD: !CTD!
REM Echos the expected path
echo CTD: %CTD%
REM Echos nothing -- understandable
for /R !CTD! %%f in (*.fs) do (echo %%f)
REM Echos nothing -- why?
for /R src\test\resources\testsuite\fast %%f in (*.fs) do (echo %%f)
REM Echos expected files
)
我试过涉及各种解决方案禁用DelayedExpansion,呼叫报表和诸如此类的东西,但我从来没有内环的工作。我知道,我可以通过一个子程序调用替换内环,但有如此的方式,使其与嵌套循环工作。
I tried various solutions involving disabling DelayedExpansion, call-statements and whatnot, but I never got the inner loop working. I know that I could replace the inner loop by a subroutine call, but there gotta be a way to make it work with nested loops.
推荐答案
如果你使用 PUSHD!CTD!
和 POPD
,并让 FOR / R
默认使用当前目录?
What if you used pushd !CTD!
and popd
, and let FOR /R
default to using the current directory?
这篇关于嵌套批次循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文