title: Python: To read files from a folder according to the date as specified on the filename and sort
body: <p>I have files in a folder which named according to the date and time it recorded: for example: <code>Test_20150925_181323.data</code> [Here on the file name <code>20150925</code> is the date (2015/09/25) and <code>181323</code> is the time (18 hr 13 min 23 sec)]. Likewise I have more than 20 files.</p>
  
  <p>I want to do the following:</p>
  
  <ol>
  <li>Read the files according to increasing order of date and time.</li>
  <li>From each file take the values between lines 11 and 21 (these are values recorded in two columns)</li>
  <li>Put those values in two arrays say<code>timevalues=[]</code> and <code>yvalues=[]</code>.</li>
  <li>Then read the next file do the same and append the values between <code>line11</code> and <code>line12</code> to <code>timevalues</code> and <code>yvalues</code>.</li>
  <li>Finally I should have two arrays, timevalues and yvalues in which the data (between lines 11 and 21 from each file) appended according to the time it recorded.</li>
  </ol>
  
  <p>My attempt:</p>
  
  <pre><code>import numpy as np
  import re, os
  import pandas as pd
  from os import walk
  
  path = r'C:\Users\Data1\\'
  for data_file in sorted(os.listdir(path)):
      print data_file
  times = []
  yvals = []
  
  for line in data_file.readlines()[11:21]: # read lines from 11 to 21
      column = line.split('\t')
      times.append(column[0])
      yvals.append(column[1])
      #print times
      #print yvals
  </code></pre>
  
  <p>This is always giving error message:  </p>
  
  <pre><code>for line in data_file.readlines()[11:21]: # read lines from 11 to 21
  AttributeError: 'str' object has no attribute 'readlines'.
  </code></pre>
  
  <p>Also, I am not sure if this is the right way to read the files according to the time on its filename.</p>