title: Iterating through directories with Python
body: <p>I need to iterate through the subdirectories of a given directory and search for files. If I get a file I have to open it and change the content and replace it with my own lines.</p>
  
  <p>I tried this:</p>
  
  <pre><code>import os
  
  rootdir ='C:/Users/sid/Desktop/test'
  
  for subdir, dirs, files in os.walk(rootdir):
      for file in files:
          f=open(file,'r')
          lines=f.readlines()
          f.close()
          f=open(file,'w')
          for line in lines:
              newline = "No you are not"
              f.write(newline)
          f.close()
  </code></pre>
  
  <p>but I am getting an error. What am I doing wrong? </p>