Chmod issue to change file permission using python

后端 未结 3 2017
别跟我提以往
别跟我提以往 2021-01-03 04:37

I am looking to change the file permission to all files to read write and execute for all the users in a directory using a python script. However, after running the script w

3条回答
  •  温柔的废话
    2021-01-03 05:35

    The recommended solution didn't work on Python3 (modules not available). I took a different approach, to use the Windows command line.

    In my case, I needed the "LOCAL SERVICE" account to have permission. I did:

        import subprocess
        args = ["icacls", directory,
                "/grant:r", 'LOCAL SERVICE:(OI)(CI)MF']
        subprocess.check_call(args)
    

    Note that this permission seems to only work when set on a directory. For security reasons, it would also be a good idea to ensure that "directory" actually exists.

    Also note that "LOCAL SERVICE" might go by a translated name. In German locale, for example, it is "Lokaler Dienst."

提交回复
热议问题