Okay guys, let my try to explain my problem:
I start with a line from where I start 2 different functions
setlocal EnableDelayedExpansion
for %%i in ("C:\*.*") do (
call :function1 "%%~i"
call :function2 "%%~i"
)
goto :eof
In function1, at a certain point I DO a SET in a local environment:
setlocal EnableDelayedExpansion
...
...
set name1=blabla
endlocal & SET name=%name1%
echo %name%
goto :eof
The echo does return my variable. Now onto my problem.
I quit function one and i go to function 2 (see first code-segment)
I can’t call the variable form here. I tried in the function2, I tried before function2 is called, but both didn’t resolve the issue.
My guess is a have set only a local variable for function1. I search the nets but i read that the line “endlocal & SET name=%name1%” should have solved my issue.
I hope I have explained it well, all help appreciated!
I’m not sure where your problem lies since this works perfectly:
outputting:
Are you certain that, when you used
namein the main areas, you used!name!instead of%name%?If you used the
%name%variant, that would be evaluated when the entireforloop was read, not at the time when you used it (in other words, it would be blank). You can see that in the output ofORIGNAMEin themainline.I’m not certain that’s the case since you are using delayed expansion. But, just in case, I thought I’d mention it. I always use delayed expansion and I always used the
!variants of the environment variables since it more closely matches how I expect a shell to work.In any case, the code I’ve given works fine so you may want to fiddle with that to see if you can incorporate it into your own.