Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33317
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <mail@timgolden.me.uk> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'attributes': 0.07; 'deprecated': 0.07; 'subject:file': 0.07; 'errno': 0.09; 'ioerror': 0.09; 'lawrence': 0.09; 'open()': 0.09; 'throw': 0.09; 'cc:addr:python-list': 0.10; 'cases': 0.15; "'w'": 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'luck,': 0.16; 'message-id:@timgolden.me.uk': 0.16; 'old- style': 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; 'subject:windows': 0.16; 'tjg': 0.16; 'wrote:': 0.17; 'basically': 0.17; '>>>': 0.18; 'windows': 0.19; 'permission': 0.20; 'file.': 0.20; 'trying': 0.21; 'regardless': 0.21; "i'd": 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'machine': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '"no': 0.29; "i'm": 0.29; 'checks': 0.30; 'mode': 0.30; '(and': 0.32; 'file': 0.32; 'not.': 0.32; 'could': 0.32; 'print': 0.32; 'received:192.168.100': 0.33; 'another': 0.33; 'open': 0.35; 'doing': 0.35; 'but': 0.36; 'does': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'some': 0.38; 'received:192': 0.39; 'application': 0.40; 'received:192.168': 0.40; 'skip:n 10': 0.63; 'contents.': 0.65; 'from:addr:mail': 0.71; 'hand': 0.82; '13:': 0.84; 'distinguish': 0.84; 'try,': 0.84; 'ali': 0.95 |
| Date | Wed, 14 Nov 2012 09:06:11 +0000 |
| From | Tim Golden <mail@timgolden.me.uk> |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 |
| MIME-Version | 1.0 |
| To | Hans Mulder <hansmu@xs4all.nl> |
| 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> |
| In-Reply-To | <50a35c73$0$6970$e4fe514c@news2.news.xs4all.nl> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3674.1352883975.27098.python-list@python.org> (permalink) |
| Lines | 26 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1352883975 news.xs4all.nl 6972 [2001:888:2000:d::a6]:59684 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:33317 |
Show key headers only | View raw
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