faqts : Computers : Programming : Languages : Python : Common Problems : Files

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 12 people (83%) answered Yes
Recently 6 of 8 people (75%) answered Yes

Entry

How can I check for read only files?

Aug 7th, 2000 05:12
unknown unknown, Roger Upole, jepler epler


You can use win32file from the win32 extensions.
import win32file
fileatt = win32file.GetFileAttributes(filename)
print fileatt & win32file.FILE_ATTRIBUTE_READONLY
----------
There's an answer already given for using win32 cals.
On unix, you would a construction like
        os.stat("file.txt")[ST_MODE] & ST_IWUSR
to check if the file-owner has write permissions.
This flag may not exist on NT, and it's not exactly the same as asking
the question "can I (whoever I am) write this file?).