The following is a list of script that should recursively open all files inside the "pruebaba" folder, but I get this error:
Traceback (last last call):
file "/home/tirengarfio/Desktop/prueba.py", line 8, in f = open (file, 'r') IOError: [Errno 21] Is the directory
This is the hierarchy:
pruebaba folder1 folder11 test1.php folder12 test1.php test2.php folder2 test1.php
script:
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()
Any idea?
python
ziiweb
source share