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
2
votes
2 answers

Delayed expansion doesn't work inside delayed expansion

I've got a script that does everything I expect it to do, apart from one line. I've done similar before, but I can't get this one to work. The code I've got is here @echo off SETLOCAL ENABLEDELAYEDEXPANSION ::Set Path to be folder of Sage…
Ricky Payne
  • 149
  • 4
  • 14
1
vote
1 answer

How to assign %%parameter to variable?

How to assign %%parameter to variable? FOR /F "tokens=1 delims= " %%A IN (connections.txt) DO ( set USER=%%A echo A=%%A echo USER=%USER% ) Output of this code: A=user1 USER= How to assign parameter %%A to variable USER?
Volodymyr Bezuglyy
  • 16,295
  • 33
  • 103
  • 133
1
vote
0 answers

Batch - Replace a String in a Loop

i´ve Problems replacing a string in a loop For example: I have a File called someBlabla.txt which has multiple lines with random sentences. Now i want to read the file line by line in a for loop and replace a specific char of a word by another. I…
1
vote
1 answer

What is the difference between % % and ! ! in a batch file?

What is the difference between these 2 pieces of code in a batch file? set str=!str:%%20= ! and set str=%str:%%20= %
Sam
  • 3,479
  • 4
  • 17
  • 17
1
vote
0 answers

batch file setlocal confusion

I am having difficulty understanding how batch file localization works. Here is an example to demonstrate my confusion @echo off set x=5 set y=1 setlocal enabledelayedexpansion if %y% GEQ 1 ( set x=6 echo %x% echo !x! ) echo…
danny
  • 1,101
  • 1
  • 12
  • 34
1
vote
1 answer

Passing arguments with special characters to batch script while delayedexpansion enabled

I need to call a script which accepts password as one of its arguments. Whenever the password contains , it is treated as a delimiter and the password will be split into two arguments and when it contains ! all the special characters are omitted. I…
1
vote
1 answer

How to locate a specific string of letters in a .BAT variable that contains a very long string?

Trying to isolate just a portion of a string contained in a .BAT variable. The String Variable !Original! contains the…
Arianax
  • 9
  • 4
1
vote
1 answer

Windows batch script: trying to extract Java version by looping on command results with pipe

I want to extract the Java version on my machine. 1/ I have an Oracle Java 8 installed and the command where java outputs this: C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe 2/ The command java -version outputs this: java…
1
vote
1 answer

Fix a batch script to handle closing parentheses inside an if block

I have a batch script to run different PHP versions under different environments. @ECHO OFF setlocal EnableExtensions EnableDelayedExpansion IF "%ANSICON%" == "" ( php7 %* ) ELSE ( php5 %* ) The problem is it breaks on the first unescaped…
CJ Dennis
  • 4,226
  • 2
  • 40
  • 69
1
vote
1 answer

String compare with batch file

A very simple batch file. I'm trying to search for file extensions that are not .txt. There will be one .txt, but the rest will be like .txt_20190607. for %%I in (\\01mtsdv130\Myapp\Log\*.*) do ( set var1=%%~xI echo %var1 if…
1
vote
0 answers

Batch file ignores If statement even when true

Somewhere i a batch file i have a piece of code that checks if a directory exists. If not then ask the user what to do. Now the strange thing is then when the directory exists i still get the question "Do you want to create the directory?" which is…
Gforse
  • 323
  • 3
  • 20
1
vote
0 answers

echo batch file array element in for-loop using the iteration variable for the index?

This question is similar to that of Echo batch file arrays using a variable for the index? but it doesn't answer my question. I have a batch file that contains a list. I am iterating through a for loop and want to print out an element from the list…
jamesD
  • 55
  • 6
1
vote
1 answer

How can I append my assemby version to the name of a folder, during the build process?

When I do a release build of my application I copy all files needed to run the program to a folder. I want that folder name to contain the assembly version. The build command I have partially works. I can get the version number into a file called…
spainchaud
  • 365
  • 3
  • 12
1
vote
1 answer

batch how to escape/ignore "!" in string variable with delayed expansion enabled

I have to rename some files with a batch but in some filenames are exclamation marks which cause a syntaxerror. Does someone have a solution for that? setlocal EnableDelayedExpansion set i=0 for %%a in (*.xml) do ( set /a i+=1 ren "%%a" !i!.new )
1
vote
1 answer

Using variable substring with variable skipped characters

I have this bit of code where the string I want it to read is thisisaname:21841569874215468432 The thing is the part before the colon is variable. It changes length based on user input. So I found a function to get string length and a function to…
Pitdroid
  • 57
  • 5
1 2 3
8 9