循环批处理脚本将不设置变量 [英] Batch script for loop won't set variable
问题描述
我有一个批处理脚本试图执行了垤获取包含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_WorkDir\var\jobs\projects\rprt_test\rprt_test\plsql') do (
set FOLDER=%%a
echo *** PROCESSING FOLDER %FOLDER% ***
)
这回声
*处理FOLDER *
,如果变量是没有得到设置,这我是pretty上验证它花费的时间太长后肯定是真实的。
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?
推荐答案
的这基本上是一个<一个重复href=\"http://stackoverflow.com/questions/12513691/cmd-get-string-from-file-and-set-it-as-a-variable-to-use-in-cd\">question问今天早些时候的。下面是我的回答对上述问题... 的
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循环工作时是非常有用。通常情况下,环整个被评为即使它跨越了一个批处理脚本的多行一个命令。
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_WorkDir\var\jobs\projects\rprt_test\rprt_test\plsql') 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屋!