循环的批处理脚本不会设置变量 [英] Batch script for loop won't set variable
问题描述
我有一个批处理脚本试图在 anthill 外执行以获取包含要编译的 plsql 的文件夹名称.
I have a batch script trying to execute out of anthill to get the folder names containing plsql to be compiled.
for /F %%a in ('dir /b D:AHP_WorkDirvarjobsprojects
prt_test
prt_testplsql') do (
set FOLDER=%%a
echo *** PROCESSING FOLDER %FOLDER% ***
)
这回响了* 处理文件夹 *
好像变量没有被设置,我很确定这是在花费太长时间验证之后是正确的
as if the variable is not getting set, which I'm pretty sure is true after spending way too long on verifying it
所以……我做错了什么?
So...What am I doing wrong?
推荐答案
这本质上是 今天早些时候提出的问题.这是我对上述问题的回答...
This is essentially a duplicate of a question asked earlier today. Here's my answer from said question...
您需要查看批处理文件的 EnableDelayedExpansion 选项.来自上述链接:
You'll want to look at the EnableDelayedExpansion option for batch files. From the aforementioned link:
延迟变量扩展在使用 FOR 循环时通常很有用.通常,即使整个 FOR 循环跨越批处理脚本的多行,它也会被视为单个命令.
Delayed variable expansion is often useful when working with FOR Loops. Normally, an entire FOR loop is evaluated as a single command even if it spans multiple lines of a batch script.
所以你的脚本最终看起来像这样:
So your script would end up looking something like this:
@echo off
setlocal enabledelayedexpansion
for /F %%a in ('dir /b D:AHP_WorkDirvarjobsprojects
prt_test
prt_testplsql') do (
set FOLDER=%%a
echo *** PROCESSING FOLDER !FOLDER! ***
)
作为替代方法,只需在内部循环中使用 %%a
变量,而不是创建新变量.
As an alternative, just use the %%a
variable in your inner loop, rather than creating a new variable.
这篇关于循环的批处理脚本不会设置变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!