title: How to read multiple files from a folder, combine the data in a single file, and add a variable with names of original files?
body: <p>I have a folder with 80 log files and their names are years they were created (example <code>2008P1.log</code>, <code>2008P2.log</code>, <code>2009P1.log</code>, etc.). Each file has a single column of data with more than 100000 rows. I want to put all these data in a single file in a sequence of their name(year wise).</p>
  
  <p>The sequence would be the year they were created, oldest first, latest last.</p>
  
  <p>Also I need an additional column in new file with the name of the file they were taken from.</p>
  
  <p>I need to do this with Python or R.</p>
  
  <p>Files:</p>
  
  <pre><code>2008
  2008P1
  2008p2
  2009P1
  2009p3
  .
  .
  .
  .
  .
  2019P3
  </code></pre>
  
  <p>Data in file:</p>
  
  <pre><code>$h|fffff|P|....
  $C|fffff|P|....
  .
  .
  .
  .
  .
  </code></pre>