delayedvariableexpansion

Cmd and exclamation marks - Part II

喜夏-厌秋 提交于 2019-11-28 05:25:26
问题 I'm really wondering why my string replacement procedure works when parsing text files containing any special characters including exclamation marks. I expected that delayed variable expansion would switch off special meaning of ampersand, percent sign etc. but will fail instead for exclamation marks... Code: @echo on & setlocal ENABLEEXTENSIONS set "InFile=%~1" set "OutFile=%~2" set "Replace=%~3" CALL :ParseCue "%%InFile%%" "%%OutFile%%" "%%Replace%%" endlocal &GOTO:EOF :ParseCue @echo on &

windows batch SET inside IF not working

我怕爱的太早我们不能终老 提交于 2019-11-26 16:10:41
when I'm running this script (from a .bat file): set var1=true if "%var1%"=="true" ( set var2=myvalue echo %var2% ) I always get: ECHO is on. Meaning the var2 variable was not really set. Can anyone please help me understand why? jeb var2 is set, but the expansion in the line echo %var2% occurs before the block is executed. At this time var2 is empty. Therefore the delayedExpansion syntax exists, it uses ! instead of % and it is evaluated at execution time, not parse time. Please note that in order to use ! , the additional statement setlocal EnableDelayedExpansion is needed. setlocal

Arrays, linked lists and other data structures in cmd.exe (batch) script

随声附和 提交于 2019-11-26 01:17:33
问题 I was playing with cmd.exe, but in its help I didn\'t find any info, how to define arrays. I have found, how to define simple variables: set a=10 echo %a% But, I want to create arrays, linked list etc... So, does it able in cmd.exe ( I mean: does in cmd.exe exist any array keywords? ) I want to realize some algorithms as: bubble sort quick sort gnome sort etc... So, I also want to know, does Cmd.exe have references or instances, structs etc? Cause its help not full in: /? Could Cmd.exe be

Example of delayed expansion in batch file

不打扰是莪最后的温柔 提交于 2019-11-25 21:57:13
问题 Can someone give me an example of where a batch script would act differently with or without delayed expansion? Are there any situations where you would NOT want to use delayed expansion? Thanks. 回答1: Look at the following examples... Example 1: The following code DOESN'T use delayed expansion, so the variables in the for loop are expanded only one time. This means that %Count% will always expand to 0 in each iteration of the loop, no matter what we do to it with the set command: @echo off

Variables are not behaving as expected

不想你离开。 提交于 2019-11-25 21:34:19
问题 I\'ve been wrestling trying to get the syntax right on this batch file and I cannot figure out why some things aren\'t working. The variable i is not getting incremented each time I do it. Concatenation on strc doesn\'t seem to concatenate. Here is my code: set i=0 set \"strc=concat:\" for %%f in (*.mp4) do ( set /a i+=1 set \"str=intermediate%i%.ts\" set strc=\"%strc% %str%|\" ffmpeg -i \"%%f\" -c copy -bsf:v h264_mp4toannexb -f mpegts \"%str%\" ) set strc=\"%strc:-1%\" ffmpeg -i \"%strc%\"