Changing file access

I know I can check the file access with os.access(), however, I cannot figure out how to set the file access. How can I do this?

There’s a SetFileAttributes method in the win32api module in the pywin32 package. That might do what you need.

Win32 would probably do it, but the standard lib can handle it.


>>> import os, stat
>>> os.chmod(r'D:	emp\blah.txt', stat.S_IWRITE) # Changes it to writeable
>>> os.chmod(r'D:	emp\blah.txt', stat.S_IREAD) # Changes it to read-only

Yup, if you only need to manipulate the read-only flag, chmod will work fine. For anything else you’ll need win32.

Worked like a charm. I must have missed the chmod method. Thanks.