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
1 answer

Batch file question: How can I load a text table from a file (with exclamation marks) into a global array?

My goal is to load a text file into a global array, and the file contains exclamation marks. I want to then bubble sort the array, and save the contents to a new file. Unfortunately I cannot even get past loading data into an array. I tried using…
0
votes
2 answers

Parsing incomming parameters in batch inside for loop with shift

I am trying to write "bootstrapper" script which parses and passes arguments into further applications in my framework. The minimal, reproducable example below, actual application is much more complicated The basic syntax for that script…
PiotrK
  • 4,210
  • 6
  • 45
  • 65
0
votes
1 answer

Statements structure to automate folder-tree creation in a batch script

I'm trying to automate my folder-tree creation, where I request to user the year (that can be more than one), and after that I create folder from 01 to 12 (January to December) inside the year folder. Into of each month's folders, I'd can be create…
0
votes
3 answers

batch for /f to iterate over all available drives to seach folder

I am writing simple script to check if somefolder exists in available drives. however %%G always shows empty string when concat with ":\somefolder" if I just echo %%G it shows all the available drives. I am new to batch scripting , not sure what…
Abhay
  • 564
  • 6
  • 14
0
votes
0 answers

Evaluate an evaluation using delayed expansion to make a variable value usable as a variable (from external batch file)

When I first started trying to build this, as a way of keeping an external file holding variables for IP addresses so I only ever had to edit one list, I felt I was doing something wrong. But then it worked. However it also outputted The system…
ja_him
  • 417
  • 1
  • 4
  • 20
0
votes
1 answer

Batch file - creating a string of numbers based on a word count in a variable

Trying to create a batch file that creates a string of numbers based on the number of words in a sentence. I have a variable that contains a varying number of words, eg: sentence="this is a sentence" The string I need to generate would be "1 2 3 4"…
Jay Ott
  • 3
  • 2
0
votes
0 answers

Need assistance with delayed expansion

I'm trying to make a bat file that localizes labels in a custom extension file I made and gets an output, the problem is that since there is apparently no way to increase a variable in a FOR loop without starting a local environment, I cannot do…
DarkMesa
  • 15
  • 1
  • 6
0
votes
2 answers

Batch: Reading values from .properties file that contain special characters

I have two files. values.properties user=username password=Password1234! mybatch.bat SETLOCAL EnableDelayedExpansion For /F "tokens=1,2 delims==" %%A IN (path/values.properties) DO ( IF "%%A"=="user" set user=%%B IF "%%A"=="password" set…
bogdanov
  • 113
  • 3
  • 14
0
votes
1 answer

Find the latest sub-folder within a directory only if that directory exists batch script

I am trying to find most recent sub-folder within a directory only if that directory exists. My code does not give me any output when I use FOR loop within IF statement. Here is my code - @echo off IF EXIST "D:\MyDirectory" ( FOR /F "delims="…
0
votes
2 answers

Inexplicable behavior caused by addition of for-loop inside else case of a function while trying to fix nested delayed expansion problem

Foreword I'm new to batch and have been doing it for about 2 weeks. My function isn't following what I would consider normal program flow rules when I add a specific for loop to it. When the for loop is removed, the function follows what I expect…
0
votes
2 answers

usebackq without delayedexpansion

The following creates a numbered list of links from a remote directory like 1 Link!1 2 Link!2 3 Link!3 4 Link!4 5 Link!5 . @echo off setlocal ENABLEDELAYEDEXPANSION megals --reload /Root/ set /p var1="enter folder name: " & megals /Root/var1 set…
0
votes
1 answer

Batch script with nested expansions not working

I'm trying to set a variable with the result of a nested variable expansion. month is an array of month names, from January (01) to December (12). monthNow holds the current month's code (e.g., 01). Here is my code: @echo off setlocal…
0
votes
1 answer

Manipulation on delayed expansion string variable is failing

I am trying to find a particular line from an XML file and extract the value using string manipulation operations. Below is the code I am trying. @echo off setlocal enabledelayedexpansion ::Expected line is "c:\temp\file1" for…
0
votes
1 answer

How can I pass an exclamation mark to a call-label routine in batch scripts and delayedexpansion is on?

I've read this post, which helps in most cases, and this post, which seems a duplicate, but I couldn't get it to work. Disclaimer: disabling/enabling delayed expansion works as workaround but that's annoying to do, unless the whole script can be…
Abel
  • 56,041
  • 24
  • 146
  • 247
0
votes
2 answers

Dynamic variable syntax with delayed expansion

In an attempt to reuse code I am trying to use dynamic variables to test a condition but am unable to get the result I need. I'm using delayed expansion. 1 Outside the for loop: 2 set "H_HEADER=FALSE" 3 set "SUB_TRANSTYPE=#" 4 5 …
ash
  • 3
  • 2
1 2 3
8 9