Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: How to Check Write Access of a Folder on Windows

7 views
Skip to first unread message

Tim Golden

unread,
Aug 12, 2011, 6:52:44 AM8/12/11
to pytho...@python.org
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 finnicky 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

0 new messages