setlocal ENABLEDELAYED EXPANSION - what does this actually do?

Can anyone help me understand in detail?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
It is setlocal EnableDelayedExpansion (case insensitive, but only two words).
As the name tells, the setting enables a delayed expansion - of variables.
By default a batch file is executed line per line, and variables embedded in percent signs (like %ThisVar% are expanded (replaced by their content) immediately.
Now there are statement constructs which build "a single line" but contain multiple statements. FOR loops for example. Something like
setlocal EnableDelayedExpansion
for %%a in (1 2 3 4) do (
   set data=Data is %%a
   echo With percent: %data%
   echo delayed expansion: !data!

Open in new window

Delayed Expansion enables the second notation with exclamation marks.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewIT / Software Engineering ConsultantCommented:
Here are a couple of sites I have used in the past (and present for reference) to expand my knowledge of DOS BAT commands and techniques.  Bookmark these for reference, and also check out the links related to this question.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
I've explained some of the context in my article .
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
May I ask what led you to grading with "B" only?
Asher00017Author Commented:
I am very sorry. Must be a mistake since i was in a hurry! It was surely an "A".
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.