Using os
:
import os
def change_permissions_recursive(path, mode):
for root, dirs, files in os.walk(path, topdown=False):
for dir in [os.path.join(root,d) for d in dirs]:
os.chmod(dir, mode)
for file in [os.path.join(root, f) for f in files]:
os.chmod(file, mode)
If you just want to make them writable additional to the flags:
import os, stat
def get_perm(fname):
return stat.S_IMODE(os.lstat(fname)[stat.ST_MODE])
def make_writeable_recursive(path):
for root, dirs, files in os.walk(path, topdown=False):
for dir in [os.path.join(root, d) for d in dirs]:
os.chmod(dir, get_perm(dir) | os.ST_WRITE)
for file in [os.path.join(root, f) for f in files]:
os.chmod(file, get_perm(file) | os.ST_WRITE)
If you are on Windows, this might not work correctly, see the documentation of os.chmod
.