Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20976

Re: check if directory is writable in a portable way

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'permissions': 0.04; 'subsequent': 0.13; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message- id:@tim.thechases.com': 0.16; 'oserror:': 0.16; 'received:50': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'possibly': 0.19; "haven't": 0.20; 'maybe': 0.21; 'header:In-Reply-To:1': 0.22; 'tests': 0.25; 'cc:2**0': 0.26; 'depends': 0.28; 'universal': 0.29; 'cc:addr:python.org': 0.29; 'unable': 0.30; "i've": 0.32; 'header:User-Agent:1': 0.33; 'file': 0.34; 'try:': 0.34; 'something': 0.35; 'but': 0.37; 'either': 0.37; 'should': 0.38; 'skip:o 20': 0.38; 'files': 0.39; 'fail': 0.39; 'except': 0.39; '(1)': 0.40; 'results': 0.64; 'encountered': 0.73; 'andrea': 0.84; 'ugly,': 0.84
Date Tue, 28 Feb 2012 05:34:59 -0600
From Tim Chase <python.list@tim.thechases.com>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16
MIME-Version 1.0
To Andrea Crotti <andrea.crotti.0@gmail.com>
Subject Re: check if directory is writable in a portable way
References <4F4CA76B.5040408@gmail.com>
In-Reply-To <4F4CA76B.5040408@gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Source
X-Source-Args
X-Source-Dir
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.223.1330431047.3037.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1330431047 news.xs4all.nl 6846 [2001:888:2000:d::a6]:54397
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20976

Show key headers only | View raw


On 02/28/12 04:07, Andrea Crotti wrote:
> How should I check if I can create files in a directory?
>
> So maybe the only solution that works is something like
> try:
>       open(path.join('temp', 'w'))
> except OsError:
>       return False
> else:
>       os.remove(path.join('temp'))
>       return True

It depends on the system & location.  It's possible to set up 
directories with permissions that allow you to create files but 
not delete them, in which case you'd either (1) create the file 
and possibly fail on subsequent tests because the file already 
exists; or (2) litter the directory with tmpnam()-like results 
that you were unable to delete.

It's ugly, I've encountered it, and haven't found a good 
universal solution myself.

-tkc



Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: check if directory is writable in a portable way Tim Chase <python.list@tim.thechases.com> - 2012-02-28 05:34 -0600

csiph-web