Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'permissions': 0.04; 'apis': 0.07; 'emulate': 0.07; 'modules.': 0.07; 'python': 0.08; 'from:addr:timgolden.me.uk': 0.09; 'from:name:tim golden': 0.09; 'message-id:@timgolden.me.uk': 0.09; 'pywin32': 0.09; 'api': 0.09; 'win32': 0.12; 'logic.': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'unfamiliar': 0.16; 'url:timgolden': 0.16; 'win32api': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.16; 'subject:Windows': 0.18; 'say,': 0.19; 'cc:no real name:2**0': 0.20; 'trying': 0.21; 'extension': 0.21; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; '(or': 0.23; 'incorrect': 0.23; 'creating': 0.25; 'windows': 0.26; 'function': 0.27; 'depends': 0.28; 'bit': 0.28; 'temporary': 0.29; 'cc:addr:python.org': 0.30; 'ctypes': 0.30; 'folder.': 0.30; 'get.': 0.30; 'tjg': 0.30; 'yes.': 0.30; 'modules': 0.31; 'changes': 0.31; 'least': 0.31; 'hi,': 0.32; 'does': 0.32; "isn't": 0.33; 'actually': 0.33; 'there': 0.33; 'header:User- Agent:1': 0.34; 'causing': 0.34; 'quite': 0.34; 'pretty': 0.35; 'apply': 0.35; 'trouble': 0.35; 'folder': 0.35; 'subject:How': 0.35; 'file': 0.36; 'url:python': 0.36; 'question': 0.36; 'another': 0.37; 'using': 0.37; 'run': 0.37; 'but': 0.37; 'could': 0.38; 'some': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'correctly': 0.39; 'option': 0.39; 'user': 0.39; "there's": 0.39; "i'd": 0.40; 'where': 0.40; 'charset:windows-1252': 0.60; 'your': 0.61; 'hope': 0.61; 'results': 0.61; 'our': 0.63; 'from:addr:mail': 0.64; 'harder': 0.64; 'yourself': 0.67; 'want,': 0.71; 'subject:Access': 0.84; 'subject:Write': 0.84; 'stamp': 0.91; 'subject,': 0.91; 'to:none': 0.93; 'subject:Check': 0.93 Date: Fri, 12 Aug 2011 11:52:44 +0100 From: Tim Golden User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 CC: python-list@python.org Subject: Re: How to Check Write Access of a Folder on Windows References: <21581D39FA3BDF40904D75AF9653CE2606BC8B29@blrex.prog.altair.com> In-Reply-To: <21581D39FA3BDF40904D75AF9653CE2606BC8B29@blrex.prog.altair.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313146373 news.xs4all.nl 23971 [2001:888:2000:d::a6]:45222 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11267 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