chmod directories recursively

Fabian Steiner info at fabis-site.net
Tue Jul 17 19:43:45 CEST 2007


Jennifer Thacher wrote:

> Fabian Steiner wrote:
>> As far as I can see os.chmod() doesn't adjust permissions on directories
>> recusively. Is there any other possibility to achieve this aim except for
>> calling os.system('chmod -R /dir') directly?
>> 
>> Thanks,
>> Fabian
> 
> Check out os.path.walk.

Thanks for your advice. This pointed me into the right direction.
For those who are interested the function passed to os.path.walk looks like
this:

def _chownRecursive(arg, dirname, fnames):
    os.chown(dirname, arg[0], arg[1])
    for file in fnames:
        os.chown(os.path.join(dirname, file), arg[0], arg[1])


Fabian



More information about the Python-list mailing list