I have to store the ouput of DIR
in a variable.
This was asked before e.g. here or here or here.
They all provide an answer more or less similar
for /f "delims=" %%a in ('dir /s /b *.sln') do set "name=%%a"
indeed is the most efficient method (you can process the output of a command directly, no need for a temporary file).
%name%
will contain the full qualified file name of your file (or the last of the files, if there are more than one)