# What is Enabledelayedexpansion in batch scripting?



## er.loyaamit (Oct 14, 2010)

Hi,
I m new 2 programming & just started learning scripting. Came across "Enabledelayedexpansion" in batch , which changes the way batch file executes. I searched & read different articles but still not getting what does it do with terms like parsing & execution.

Can any 1 explain in simple words like a beginner guide?


----------



## Ninjaboi (Dec 27, 2010)

Hello er.loyaamit!

This link should give you all the info you need:

EnableDelayedExpansion

It provides examples, explanations, and descriptions of what "EnableDelayedExpansion" does and how to utilize it in your code.


----------



## Squashman (Apr 14, 2005)

Basically what it comes down to is this.
When a batch file is executing commands, all the variables within the command are populated with their current value before execution. Variables are expanded to their value before the command is executed. Not when the command is executed.

Now lets say inside a for loop you are using a variable a couple of times and manipulating that variable inside the for loop and assigning it to different variables. All the variables already defined inside the for loop are immediately populated before the For Loop is executed. So you need Delayed expansion so that the variables are not defined or expanded until the command is executed.

Batch Files - Variable Expansion in FOR Loops
Batch files - The SET command: Windows NT 4..Windows 7 Syntax


----------

