以下的嵌套for循环让我抓狂(在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、调用语句等解决方案,但我从未让内部循环正常工作。我知道可以通过子程序调用来替换内部循环,但必须有一种方法可以使用嵌套循环使其正常工作。