Hi,

Is it possible to change a folder permission using python.


Brgds,

kNish

Yes you can, with os.chmod like this

import os
import stat

try:
    # create a folder with mode 777 (octal)
    os.mkdir("montypython")
    # change mode to 577
    os.chmod("montypython",  0577) # don't forget the 0
    # get the current mode and print it
    print stat.S_IMODE(os.stat("montypython")[stat.ST_MODE])
finally:
    # in any case, attempt to remove directory
    try:
        os.rmdir("montypython")
    except OSError:
        pass

Also system calls would work:

import os

os.system('chmod 755 /usr/myfile')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.