Batch file for loop keep variable data after goto:eof
<p>So I have a subroutine function that opens a folder dialog I can output the folder path location to a txt file just fine. But Can't seem to store the location in the variable.</p>

<pre><code>@echo off
setlocal
Call :OutputSelect
echo %location%
pause
endlocal
exit

:OutputSelect
setlocal enabledelayedexpansion
set "fchooser=%temp%\fchooser.exe"
if exist "!fchooser!" del "!fchooser!"
&gt;"%temp%\c.cs" echo using System;using System.Windows.Forms;
&gt;&gt;"%temp%\c.cs" echo class dummy{[STAThread]
&gt;&gt;"%temp%\c.cs" echo public static void Main^(^){
&gt;&gt;"%temp%\c.cs" echo FolderBrowserDialog f=new FolderBrowserDialog^(^);
&gt;&gt;"%temp%\c.cs" echo f.SelectedPath=System.Environment.CurrentDirectory;
&gt;&gt;"%temp%\c.cs" echo f.Description="Select Output Folder";
&gt;&gt;"%temp%\c.cs" echo f.ShowNewFolderButton=true;
&gt;&gt;"%temp%\c.cs" echo if^(f.ShowDialog^(^)==DialogResult.OK^){Console.Write^(f.SelectedPath^);}}}
for /f "delims=" %%I in ('dir /b /s "%windir%\microsoft.net\*csc.exe"') do (
if not exist "!fchooser!" "%%I" /nologo /out:"!fchooser!" "%temp%\c.cs" 2&gt;NUL
)
del "%temp%\c.cs"
setlocal disabledelayedexpansion    
for /f "delims=" %%I in ('%fchooser%') do set location=%%I\
goto:eof
</code></pre>