Questions tagged [delayedvariableexpansion]

Delayed variable expansion causes a Windows batch file to evaluate variables at run time instead of parse time.

Variables in a Windows batch files are normally evaluated when the script is parsed. With delayed variable expansion, variables are evaluated at execution time instead. This is especially useful in FOR loops. To turn on, use setlocal EnableDelayedExpansion. To turn off, setlocal DisableDelayedExpansion.

127 questions
0
votes
2 answers

Evaluating a DelayedExpansion variable as a drive letter when checking for file existence

I've got this block of code that's supposed to check for USB drives, then if they have a file that tags them as one of my utility drives, it runs a robocopy sync on them to make sure they're current. The problem is it's not evaluating the path for…
0
votes
1 answer

Loop through "array" in batch file to shift elements

I have a batch file that is passed commands in the form of a string array from a Java file. The commands contain something like the following: String[] commands = {"A", "B", "C", …
DerStrom8
  • 1,311
  • 2
  • 23
  • 45
0
votes
2 answers

Inner delayed expansion in a batch script (windows)

I need to make delayed expansion inside of delayed expansion, i.e. smth like: !PARAMS[!BEFORE_LAST!]! Of course, the above is not valid, so I tried to workaround it with for-loop, but with no success: SETLOCAL EnableExtensions…
Alec
  • 1,486
  • 2
  • 14
  • 30
0
votes
2 answers

DOS Delayed expansion in concatendated command string

I have asked other questions about Concatenated commands in DOS, but am obviously not yet that confident with the full bredth of things to take into account. Can someone take a look at the below code and output on my system and see if they can…
user66001
  • 774
  • 1
  • 13
  • 36
-1
votes
1 answer

Variable name stored in delayed variable - Batch

I have: setlocal EnableDelayedExpansion var inLoopVar=hey var first=!inLoopVar! echo %!first!% This outputs ECHO OFF because %!first!% is returned as empty. How can I print "Hey" Updated and Clarified: Here is my full code with comment of what i am…
Iaim miac
  • 1
  • 2
-1
votes
1 answer

Expand Environmental Variable from runtime generated variable name

I have created a batch file that alters the PATH depending on what compiler name I pass to it. I also want to select from a number of these variables at runtime, I have another batch file where I generate the name of the appropriate environmental…
-2
votes
1 answer

How to do substitution in variables with EnableDelayedExpansion on in a batch file?

I asked this question yesterday, but it was marked as duplicate and I was given a link to a question that discusses something similar, but NOT variable substitution and substrings specifically, so I'm posting it again. I am trying to do variable…
1 2 3
8
9