title: Batch script to print last line of many files in a folder matching a file name pattern
body: <p>I have multiple text files in a folder. I would like to print the last line of each file found in the folder matching the file name pattern <code>*.Config</code> and redirect those lines to a new text file. </p>
  
  <p>The below script works for 1 text file. But at the moment I do a <strong>for</strong> loop for multiple text files and <code>%lastline%</code> prints always the same value. </p>
  
  <pre><code>@echo off &amp; setlocal EnableDelayedExpansion 
  
  for /f %%i in ('dir /b *.Config') do (
      for /r "delims==" %%a in (%%i) do (
          set lastline=%%a
          echo %lastline% is the last line of %%i &gt;&gt; vResult.txt
      ) 
  )
  </code></pre>