嵌套批处理循环 [英] Nested batch for loops

查看:29
本文介绍了嵌套批处理循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下嵌套的 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	est
esources	estsuite

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	est
esources	estsuitefast %%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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆