chmod 777 to python script

13,730

os.chmod takes a single filename as argument, so you need to loop over the filenames and apply chmod:

files = ['file1', 'file1/tmp', 'file2', 'file2/tmp', 'file3', 'file3/tmp']
for file in files:
    os.chmod(file, 0o0777)

BTW i'm not sure why are you setting the permission bits to 777 -- this is asking for trouble. You should pick the permission bits as restrictive as possible.

Share:
13,730

Related videos on Youtube

Xandy
Author by

Xandy

Updated on June 04, 2022

Comments

  • Xandy
    Xandy almost 2 years

    Trying to translate linux cmd to python script

    Linux cmds:

    chmod 777 file1 file1/tmp file2 file2/tmp file3 file3/tmp
    

    I know of os.chmod(file, 0777) but I'm not sure how to use it for the above line.

  • Xandy
    Xandy about 6 years
    Ahh, thank you. I was thinking there was some hidden level to chmod. I'm just translating a process already in place. Thanks!!