title: How to execute a python script across all directories
body: <p>I wrote the following script to anonymize e-mail addresses in a txt file:</p>
  
  <pre><code>import io, os, sys
  import re
  
  def main():
  
  try:
      # Open the file.
      myfile = open('emails.txt', 'r')
  
      # Read the file's contents.
      content = myfile.read()
      content = re.sub(r'.+(?=@.+\.(com|edu))', "xxxx", content)
  
      myfile = open('emails.txt', 'w')
      myfile.write(content)   
      # Close the file.
      myfile.close()
  
  except IOError:
      print('An error occured trying to read the file.')
  
  except:
      print('An error occured.')
  
  main()
  </code></pre>
  
  <p>I was wondering how I could make this work for all files in a directory and its subdirectories. </p>