[python-win32] checking file permission on network share

Steffen Frömer steffen.froemer at gns-systems.de
Wed Aug 31 14:38:47 CEST 2011


Hello,

i try to check, if a file on network-share is read only. I tried 
different ways.


filename = r'//server/share/filename.txt'

1:
import win32api, win32con

fileAtt = win32api.GetFileAttributes(filename)
if (fileAtt & win32con.FILE_ATTRIBUTE_READONLY):
     print("READONLY")

2:
import os, stat

fileAtt = os.stat(filename)[0]
if (not fileAtt & stat.S_IWRITE):
     print("READONLY")

3:
import os
if not os.access(filename, os.W_OK):
     print("READONLY")

all variants give me same result, that file is NOT readonly, but in real 
it is.
The network-share is a Samba-Service with share-option "read only = yes"

i also tried to set "read only"-Flag in windows and copy this file to 
network share.

Is there a solution, to find out, if my file is writeable or not?

Regards,
Steffen


More information about the python-win32 mailing list