title: Batch - Write output of DIR to a variable
body: <p>I have to store the ouput of <code>DIR</code> in a variable.</p>
  
  <p>This was asked before e.g. <a href="https://stackoverflow.com/questions/39957309/batch-store-output-of-dir-command-into-variable-directory-listing">here</a> or <a href="https://stackoverflow.com/questions/28663803/batch-assign-command-output-with-variables-to-variable">here</a> or <a href="https://stackoverflow.com/questions/44307834/outputting-batch-command-to-variable">here</a>.</p>
  
  <p>They all provide an answer more or less similar to what I'm using right now:</p>
  
  <pre><code>%= Find the *.sln file and write its path to the file temp.temp =%
  DIR /s/b *.sln &gt; temp.temp
  
  %= Read out the content of temp.temp again to a variable =%
  SET /p texte=&lt; temp.temp
  
  %= Remove the temp.temp file =%
  DEL temp.temp
  
  %= Get only the filename without path =%
  FOR %%A IN ("%texte%") DO (
      SET Name=%%~nxA
  )
  </code></pre>
  
  <p>But in my case I'm sure that the ouput of <code>DIR /s/b *.sln</code> will allways be a <strong>one-liner</strong>. To me it looks a bit ugly to have to <br>
  a) store the ouput in an external file and <br>
  b) run a <code>FOR</code> loop over it though I already know it will only have one line.</p>
  
  <p><strong>Is there any direct/simpler way to do this?</strong></p>