Detect file is locked - windows

Aahz aahz at pythoncraft.com
Thu Nov 15 17:01:45 CET 2012


In article <mailman.3676.1352887368.27098.python-list at python.org>,
Tim Golden  <mail at timgolden.me.uk> wrote:
>On 14/11/2012 00:33, Ali Akhavan wrote:
>>
>> I am trying to open a file in 'w' mode open('file', 'wb'). open()
>> will throw with IOError with errno 13 if the file is locked by
>> another application or if user does not have permission to open/write
>> to the file.
>> 
>> How can I distinguish these two cases ? Namely, if some application
>> has the file open or not.
>
>Can I ask what you expect to do differently in each of those cases? In
>other words, if you can't access the file, you can't access it. (Not to
>dismiss your question; I just wonder how you're going to handle the
>different cases)

Real-life use case for user-requested operation: if no permission, skip
the file "permanently" (until it changes, at least); if locked, place in
retry loop.

And in response to your other post, you absolutely want to use
CreateFileW()...  ;-)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"LL YR VWL R BLNG T S"  -- www.nancybuttons.com


More information about the Python-list mailing list