Is it possible to pull variable out of setlocal and endlocal pair in for loop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sincos2007
Posts: 44
Joined: 05 Apr 2019 05:52

Is it possible to pull variable out of setlocal and endlocal pair in for loop

#1 Post by sincos2007 » 07 May 2019 13:55

Code: Select all

:test5
setlocal DisableDelayedExpansion

set /a "n=0"
for /f "delims=" %%i in (txt1.txt) do (
	set "line=%%i"

	setlocal EnableDelayedExpansion
	set "str_out=!str_out! / number{!n!}-{!line!}"
	rem debug
	echo !str_out!
	endlocal&set "str_out_1=%str_out%"

	set /a "n+=1"

	echo Position 1:
	echo str_out_1=%str_out_1%
)

echo Position 2:
echo str_out_1=%str_out_1%

endlocal
goto :eof
I always feel there has a way to reach this title, without help of io redirection. I believe for loop is powerful.

Post Reply