Contents of variable set from for loop variable substitution refer to previous run in Windows batch script -


if code saved file tst.bat:

@echo off %%a in (%1) (     echo "%%~fa"     set b=%%~fa     echo "%b%" ) 

and invoked twice follows, i'd expect this:

c:\windows\temp>tst.bat abc "c:\windows\temp\abc" "c:\windows\temp\abc"  c:\windows\temp>tst.bat xyz "c:\windows\temp\xyz" "c:\windows\temp\xyz" 

but instead, this:

c:\windows\temp>tst.bat abc "c:\windows\temp\abc" ""  c:\windows\temp>tst.bat xyz "c:\windows\temp\xyz" "c:\windows\temp\abc" 

do have wrong expectations?

once upon time, wrote great intro answer i'm give, can't find it. basically, if want have variables inside for loop update loop, need use delayedexpansion.

@echo off setlocal enabledelayedexpansion %%a in (%1) (     echo "%%~fa"     set b=%%~fa     echo "!b!" ) 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -