title: iterating through files in a directory
body: <p>My code supposed to get the last modified file and print in to screen while it keeps running until a new file is modified and it prints it to screen, but I keep getting an typeError.
  TypeError: coercing to Unicode: need string or buffer, int found.</p>
  
  <pre><code>import os, sys, re, time
  from datetime import date, timedelta, datetime
  from time import localtime
  
  files = os.listdir('dir_path')
  
  files = [f for f in files if re.search('.csv', f, re.I)]
  files.sort
  
  d = datetime.now() - timedelta(days = 30)
  d = d.timetuple()
  
  oldfiles = 0
  newfiles = 0
  for file in files:
      filetimesecs = os.path.getmtime('dir_path' + file)
      filetime = localtime(filetimesecs)
  
  if filetime &lt; d:
      oldfiles += 1
  if filetime &gt; d:
      newfiles += open(files, 'r')
      for k in newfiles:
          sys.stderr.write(k)
      while True:
          time.sleep(2)
          print"new: %s" % newfiles
  </code></pre>