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:
- Decide on the permission levels you want for the file.
- Use a file manager (e.g. nautilus) to select the file, then right-click on it, click on "Properties" followed by left-clicking on the "Permission" Tab. Here you can set the desired permission levels for the file.
- Next, from a Python interpreter, submit the above mentioned commands. It will return the corresponding mode value for the permission level you want. You can then use that in
pathlib.Path.chmod(mode)
command.