May I know how to define the mode in pathlib.Path.chmod(mode). I did not find any explanation or explanation links on how to define mode in python 3.6 documentation. E.g.
>>> p = Path( 'filename.ext' )
>>> p.stat().st_mode
33204
What is the meaning of the five digits either individually or together? I would like to change the value to so that Owner has execute permission. How do I work out the values to use for mode?
Alternative Solution:
I like to thank @falsetru for his answer and comments. Also, I like to share a non mathematical approach to find the "mode value" of a desired permission level that can be submitted to a pathlib.Path.chmod(mode)
command.
Here are the Steps:
pathlib.Path.chmod(mode)
command.If you follow the link (os.chmod
), you will know each bit means.
By converting the mode value to octal representation, it would be easier to read:
>>> oct(33204)
'0o100664'
33204 & S_IFREG
-> non-zero OR S_ISREG(33204)
-> True) S_IFREG
, S_ISREG
UPDATE:
stat.filemode
converts the number into a human readable format:
>>> stat.filemode(33204)
'-rw-rw-r--'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With