title: How to find files and extract time from filenames and store them in an array?
body: <p>I have a folder with several different files in it (txt, dat, jpg) and I need to read all the files with the end "triang.dat". These files contain their time on the filename as in:</p>
  
  <p>"NIK_054504_triang.dat" </p>
  
  <p>I managed to find the files and convert the times into seconds:</p>
  
  <pre><code>mypath = '/home/rmesqui/Desktop/Upleg/New/'
  
  k=0
  
  
  for file in os.listdir(mypath):
       if file.endswith("triang.dat"):
           k = k+1
  
  filenames = np.zeros(k)
  
  print filenames
  k = 0
  for file in os.listdir(mypath):
      if file.endswith("triang.dat"):
          #filenames[k] = file    
          filenames[k] = 
  float(file[4:6])*3600.+float(file[6:8])*60.+float(file[8:10])
          k = k+1
  
  timearr = np.sort(filenames)-np.min(filenames)
  </code></pre>
  
  <p>But I have to sort <strong>filenames</strong> because the procedure to read the filenames, returns out of order files. However, I need to read these files in order, since the time of the data taking is important for the rest of the program. As in, I need to have an array such as:</p>
  
  <pre><code>lat1 = np.zeros(shape=(100+3,numberOfFiles))
  </code></pre>
  
  <p>where the "+3" is the time, for our example, hour = 05, minutes = 45, seconds = 04. The "100" would be the contents of a particular column in the file.</p>
  
  <p>Thanks y'all!</p>