title: Python script to loop through all files text in directory... delete any if that's file has lines start by 1
body: <p>I'm trying to write a Python script that loops through all text files in a directory and deletes any file that has lines that start with 1.</p>
  
  <p>I tried to do it with python, but I don't know how.</p>
  
  <p>My code:</p>
  
  <pre><code>import os
  import re
  import string
  
  filedir = "C:\Users\Mr The Vinh\Downloads\ver 3.0.2.4\ver 3.0.2.4\baiviet_da_thay_link\test"
  t = 0
  for root, dirs, filenames in os.walk(filedir):
      for f in filenames:
          path = os.path.join(root, f)
          text = open(path, 'r')
          delkey = re.search(r'^1',text.read())
          if delkey:
              t = t + 1
              os.remove(path)
  
  print 'We deleted file:', t
  </code></pre>
  
  <p>when i run i saw
  Process finished with exit code 0 with no erro code</p>