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

Batch loop to create folders from a list containing environment variables

I have a file containing a list of directory paths. I want to create directories at those locations. The paths have system environment variables, set with System Properties ->Environment Variables. Like…
Adam
  • 840
  • 6
  • 24
0
votes
3 answers

Struggling to perform string substitution within a nested for loop

In a Windows cmd shell batch script, I am trying to craft a mechanism to iterate over a series of directories which all have their name in the form of x.Year-Month-Day, where x is a sequential value, from 0 up to a defined limit. I want to…
0
votes
2 answers

Return a value from a called batch file label

I have two labels in my batch file. The initial label MAIN shall stay in control, so it Calls the second label, which ends with exit /b. My script's Main label Calls the other, passing it arguments, which will be used to search strings wothin a text…
0
votes
2 answers

Cannot parse file names with ! in them but double quoted?

I've probably pushed myself into a corner here but for some reason this batch will handle pretty much any name except one with a ! in it. I cannot figure out why for the life of me what I've done wrong. If the file has a ! in the name it ignores it…
0
votes
1 answer

Delayed Expansion Inside Loop with Arithmetic Operations on Time Values

I am relatively new to batch files, and I have been trying to get the following timing routine (inspired from Arithmetic operations with HH:MM:SS times in batch file) to work: set "startTime=%time: =0%" @rem Removing milliseconds information set…
G. Rab
  • 43
  • 5
0
votes
1 answer

Problem saving string variables in .bat script

As the title says I have a problem saving (and therefore printing) string variables in my bat script. The problem occurs when I try working with strings that start and/or end with '!'. Example: @echo off pause setlocal ENABLEDELAYEDEXPANSION for /r…
user10820441
0
votes
1 answer

Getting delayed expansion value to function output

Here is a windows cmd fragment: :moveFiles @for /f %%R in ('dir /b current') do ( @echo ___ @echo Moving %%R to FTP server. %java_cmd% -jar f17ftp.jar -dput -file:%%R %select% if 1 neq 0 ( @echo…
0
votes
2 answers

Batch renaming files incrementally with special characters

I am trying to rename the episodes in a directory in an incremental way, but there are exclamation marks in some of the episodes. It will skip those files. I tried doing delayed expansion, but it didn't work. @echo off setlocal…
0
votes
1 answer

Batch array, associative array, and how to navigate in array

How can I call in batch a multiple level of array ? I want to create an array of unique value with multiples data, then I will manage to make an associative array after unyfing the values. I have a csv file with lot of value like this…
0
votes
1 answer

Enable/Disable Delayed Expansion in FOR /f loop (batch)

I am still struggling to properly understand the behaviour of Disable/EnableDelayedExpansion... I want to parse input arguments when calling something like command -a -b -c file such to finally have options=-a -b -c and filename=file. To do so I use…
mEm
  • 353
  • 3
  • 12
0
votes
1 answer

Why can't I access local variable in for loop (batch file) even with setlocal enabledelayedexpansion?

Trying to access a custom local variable in a FOR loop within a batch file, I keep getting ECHO is off. Despite that enabledelayedexpansion is set and used with !_!, as numerous guides suggest.. What may be wrong and how such trick should be…
0
votes
1 answer

Watermark Not Working For Videos With Exclamation Marks

I made a .bat script to watermark videos with the logo slowly sliding across the video from the right to the left. Here is my code: set ffmpeg="C:\ffmpeg\ffmpeg.exe" set ffprobe="C:\ffmpeg\ffprobe.exe" @echo off setlocal enableextensions…
0
votes
2 answers

how to store jpg image dimensions using for command, store the results in a var, and use the var in an imagemagick command line

I am trying to use a batch script and a for loop command to find all jpg files in the working directory and then use a second for command loop to extract the image dimensions 'wxh' value for each jpg image found and temporarily store the result in a…
0
votes
1 answer

Why batch sometimes does not process commands like CMD does and gives unexpected and different results

When I run a command from the CMD directly it works perfectly fine but when run the same command in a batch file (or Jenkins using batch) it gives me a different result and I dont understand why. To explain it simple, I'm running command below to…
0
votes
2 answers

Windows CMD Batch Script - how to avoid cutting the mark "!" in the loop

I have XML file myConfig.xml. C:\Temp\TESTxyz
mAsHER
  • 15
  • 7
1 2 3
8 9