title: Python 2.5.2: trying to open files recursively
body: <p>The script below should open all the files inside the folder 'pruebaba' recursively but I get this error:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):<br>
    File
    "/home/tirengarfio/Desktop/prueba.py",
    line 8, in 
        f = open(file,'r') IOError: [Errno 21] Is a directory</p>
  </blockquote>
  
  <p>This is the hierarchy:</p>
  
  <pre><code>pruebaba
    folder1
      folder11
         test1.php
      folder12
         test1.php
         test2.php
    folder2
      test1.php
  </code></pre>
  
  <p>The script:</p>
  
  <pre><code>import re,fileinput,os
  
  path="/home/tirengarfio/Desktop/pruebaba"
  os.chdir(path)
  for file in os.listdir("."):
  
      f = open(file,'r')
  
      data = f.read()
  
      data = re.sub(r'(\s*function\s+.*\s*{\s*)',
              r'\1echo "The function starts here."',
              data)
  
      f.close()
  
      f = open(file, 'w')
  
      f.write(data)
      f.close()
  </code></pre>
  
  <p>Any idea?</p>