How to Check Write Access of a Folder on Windows

Ayaskant Swain ayaskant.swain at gmail.com
Tue Aug 16 08:38:01 EDT 2011


Hi Tim,

Thanks for your reply. It seems this issue is related to python bug -
http://bugs.python.org/issue2528

But the patch code looks complex to me. I want to make changes only in
my python script which will read an user given directory path & check
it's write access. What is the use of posixmodule.c file?

I also went through the link that you provided -
http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html

The code section in this link has a line  -

    sd = win32security.GetFileSecurity (FILENAME,
win32security.DACL_SECURITY_INFORMATION)

Can we retrieve any write access information from this sd object in
the python script?



Thanks

Ayaskant-

-------------------------------------------------------------------------------------------------------



On 12/08/2011 11:41, Ayaskanta Swain wrote:

>* Hi,*

>* *

>* I have a requirement where I need to check the write permissions on a*

>* directory on Windows platform. I don’t want to use the python function*

>* os.access( ), since it does not work correctly on Windows. It is giving*

>* incorrect results to me.*

>* *

>* Another option of actually creating a temporary file inside the folder &*

>* then deleting it to check whether the user has write permissions or not*

>* is causing performance issues. It is slowing down our application when*

>* we have to check the permissions on hundreds of folders. It also changes*

>* the last access time stamp of the folder.*

>* *

>* So is there any other way such as using Win32API or Win32 security*

>* modules to check the permissions?*



In general, yes. Depends how finicky you want to get. I take it from

your question that you're pretty much unfamiliar with the Windows

Security APIs and structures? There's a quite a bit of information

around on the subject, but have a look at this first which is at

least Python-oriented:



http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html



The trouble is that do what you want, you need to use the AccessCheck

API (or emulate its functionality) and this isn't currently exposed by

the pywin32 modules. You could run it up yourself with ctypes or by

creating a quick extension for the purpose. Alternatively, as I say,

you could emulate by scanning the ACLs/ACEs and trying to apply some

suitable logic. Frankly, I'd have thought this was harder work :)



Hope that helps



TJG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110816/59795b61/attachment.html>


More information about the Python-list mailing list