To my surprise, a new directory with the READ-ONLY state is always created after the function ‘mkdir’ in my Windows system. I wonder, HOW I can get that state off with what function.
Is this a python question?
Sounds like a windows question?
By “read-only state”, do you mean that directory has the readonly attribute set, or do you mean that its security descriptor doesn’t grant the current user the right to add and remove files and directories?
In the latter case, the directory’s security descriptor (i.e. a record containing the owner and discretionary/system access control entries of a secured object) is determined by inheritable entries in the security descriptor of the parent directory by default. Currently, Python’s standard library has no support for managing security descriptors of secured objects on Windows. You’ll have to use the Windows API directly via PyWin32 or ctypes to modify the security descriptor. I can help with this if you’re serious and need help.
I’d be at a loss to explain the former case of the readonly attribute being set by default. The implementation of
os.mkdir() on Windows directly calls WinAPI
CreateDirectoryW(), and nothing else. This API function doesn’t support setting file attributes, and file attributes aren’t inherited from the parent directory. That said, marking a directory as readonly has few practical consequences. If the readonly attribute is set, it prevents deleting the directory, and it prevents modifying any of its alternate data streams (i.e. “$DATA” streams in NTFS). But you can still add and remove files and directories from a ‘readonly’ directory, since the index stream (i.e. “$INDEX_ALLOCATION” stream in NTFS) isn’t protected by the readonly attribute.