How to Check Write Access of a Folder on Windows

Tim Golden mail at timgolden.me.uk
Wed Aug 17 17:47:49 CEST 2011


On 16/08/2011 13:38, Ayaskant Swain wrote:
> 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?

Well.. the changes to posixmodule.c, had they been accepted, would
have meant that a call to os.access on Windows would have done the
work to determine whether or not you truly had access. As it is,
that issue has been "demoted" to a doc-and-deprecate bug.

So you either need to do the same sequence of actions (more or
less) or to simulate its effect. Certainly you can retrieve the
ACEs in the DACL via the GetFileSecurity call, and you're then
going to have to compare the effect of all the (possibly
quite complex and inherited) ACEs on the logged-in user's ability
to view the directory.

The ACEs might refer directly to the user or (more likely)
indirectly via groups, including builtins like "Domain Users"
or "Administrators". So you'd have to work out whether your user
was in one of those groups, possibly indirectly as groups can
contain groups.

Certainly all of this is do-able but it won't be trivial. I'm
sorry I can't be more helpful but I haven't had a need for this
functionality myself (even the patch to issue2528 was in response
to someone else's need similar to yours).

TJG



More information about the Python-list mailing list