Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33317
| Date | 2012-11-14 09:06 +0000 |
|---|---|
| From | Tim Golden <mail@timgolden.me.uk> |
| Subject | Re: Detect file is locked - windows |
| References | <2af436e3-1336-42ae-aa2f-9e33135a3f2c@googlegroups.com> <mailman.3659.1352855611.27098.python-list@python.org> <50a35c73$0$6970$e4fe514c@news2.news.xs4all.nl> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3674.1352883975.27098.python-list@python.org> (permalink) |
On 14/11/2012 08:55, Hans Mulder wrote:
> On 14/11/12 02:14:59, Mark Lawrence 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.
>
> I don't have a Windows machine at hand to try, but this might work:
>
> if exc.errno == 13:
> if os.access('file', os.W_OK):
> print "Locked by another process"
> else:
> print "No permission to write"
No luck, I'm afraid. os.access on Windows is basically non-functional
(and would have been deprecated if I'd actually got around to doing it).
It basically checks the old-style readonly flag and that's it. IOW,
you'd return True for a file whose attributes you could read regardless
of whether you could read/write the file contents.
TJG
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Detect file is locked - windows Ali Akhavan <a.akhavan.b@gmail.com> - 2012-11-13 16:33 -0800
Re: Detect file is locked - windows Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-14 01:14 +0000
Re: Detect file is locked - windows Hans Mulder <hansmu@xs4all.nl> - 2012-11-14 09:55 +0100
Re: Detect file is locked - windows Tim Golden <mail@timgolden.me.uk> - 2012-11-14 09:06 +0000
Re: Detect file is locked - windows Tim Golden <mail@timgolden.me.uk> - 2012-11-14 10:02 +0000
Re: Detect file is locked - windows Hans Mulder <hansmu@xs4all.nl> - 2012-11-14 12:51 +0100
Re: Detect file is locked - windows Tim Golden <mail@timgolden.me.uk> - 2012-11-14 12:09 +0000
Re: Detect file is locked - windows aahz@pythoncraft.com (Aahz) - 2012-11-15 08:01 -0800
Re: Detect file is locked - windows Tim Golden <mail@timgolden.me.uk> - 2012-11-14 11:50 +0000
csiph-web