
Re: Return ANY string across ENDLOCAL boundry - BUG!
Hi Ed,
Ed Dyreen wrote:
I can't follow this bit of code :
Code:
set "var=!var:%%=%%~A!"
set "var=!var:"=%%~B!"
for %%a in ("!LF!") do set "var=!var:%%~a=%%~L!"
for %%a in ("!CR!") do set "var=!var:%%~a=%%~C!"
Would you explain it for me

I'm not at your level

First, all (single) percents are replaces with %~A
All quotes are replaced with %~B
All <LF> are replaced with %~L
All <CR> are replaced with %~C
The <LF> and <CR> need a FOR-Loop-Var, to replace the character, as you can't place it directly between !..!
But why
Because at the end, all these replacements are replaced to their original values,
this is neccessary, as they can't stay int the return statement without this trick.
@dbenham
dbenham wrote:
Noooooooo!

I just discovered a serious bug in the "magic" code that Jeb developed here
Ok there is a bug, but it's not a problem
Simply replace the %~A, %~B %~C (and perhaps %~L) with
%~2, %~3, %~4, %~9 and change the For-Loop to %%2 (%%1 could collide with the set %~1)
Code:
rem ** Prepare for return
set "var=!var:%%=%%~2!"
set "var=!var:"=%%~3!"
for %%a in ("!LF!") do set "var=!var:%%~a=%%~9!"
for %%a in ("!CR!") do set "var=!var:%%~a=%%~4!"
rem ** It is neccessary to use two IF's else the %var% expansion doesn't work as expected
if not defined NotDelayedFlag set "var=!var:^=^^^^!"
if not defined NotDelayedFlag set "var=%var:!=^^^!%" !
set "replace=%% """ !CR!!CR!"
for %%9 in ("!LF!") do (
for /F "tokens=1,2,3" %%2 in ("!replace!") DO (
ENDLOCAL
ENDLOCAL
set "%~1=%var%" !
@echo off
goto :eof
)
)
The problem seems to be the characters, they are interpreted as flags A=a=file attributes...
jeb