[Tutor] File permissions

Daniel Yoo dyoo@hkn.EECS.Berkeley.EDU
Fri, 28 Jul 2000 09:41:20 -0700 (PDT)


On Fri, 28 Jul 2000, Jacob Williams wrote:

> With python, can you create a folder with a write only permission?
> thanks in advance!

I think it might depend on your default umask; I might be completely
mistaken on this.  If it doesn't create with write-only, you can use
os.chmod() to change permissions to what you want.  Here's a small
function to do what you want:

###
def makeWriteOnlyDir(dir_name):
  os.mkdir(dir_name)
  os.chmod(dir_name, 0333)  # represented as octal wxwxwx
###

and a test:

>>> makeWriteOnlyDir('testtest')

[dyoo@c82114-a dyoo]$ ls -l
d-wx-wx-wx    2 dyoo     dyoo         4096 Jul 28 09:40 testtest


So this works ok.  Good luck!