Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'permissions': 0.04; 'ugly': 0.07; 'to:addr:python.list': 0.09; 'to:addr:tim.thechases.com': 0.09; 'to:name:tim chase': 0.09; 'am,': 0.12; 'library': 0.13; 'subsequent': 0.13; '-tkc': 0.16; 'oserror:': 0.16; 'things?': 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; '(or': 0.22; 'fine': 0.24; 'tests': 0.25; 'guess': 0.26; 'cc:2**0': 0.26; 'code,': 0.28; 'depends': 0.28; 'universal': 0.29; 'cc:addr:python.org': 0.29; 'unable': 0.30; "didn't": 0.30; 'message-id:@gmail.com': 0.31; "i've": 0.32; 'thanks': 0.32; "isn't": 0.33; 'there': 0.33; 'header:User- Agent:1': 0.33; 'file': 0.34; 'try:': 0.34; 'something': 0.35; 'received:209.85.214': 0.36; 'received:10.0.0': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'either': 0.37; 'received:209.85': 0.38; 'think': 0.38; 'should': 0.38; 'skip:o 20': 0.38; 'files': 0.39; 'fail': 0.39; 'right,': 0.39; 'except': 0.39; 'received:209': 0.39; '(1)': 0.40; 'header:Received:6': 0.61; 'results': 0.64; 'encountered': 0.73; '11:34': 0.84; 'andrea': 0.84; 'ugly,': 0.84; 'abstracts': 0.91 Received-SPF: pass (google.com: domain of andrea.crotti.0@gmail.com designates 10.204.152.12 as permitted sender) client-ip=10.204.152.12; Authentication-Results: mr.google.com; spf=pass (google.com: domain of andrea.crotti.0@gmail.com designates 10.204.152.12 as permitted sender) smtp.mail=andrea.crotti.0@gmail.com; dkim=pass header.i=andrea.crotti.0@gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=JHYPLUHXkhpVW/XNqsyjYsYmFmlPgSBfj2pzGtZ4IWg=; b=IxUowFmIMF3NfX1m+n+e2J/Abqooi3EsshOBngkIqZ5vi00oGM1Nk8RRe8GcCMmYnf GcXY1CtfO/TDe6LxcQDd63dkmPbk6E19FSTZwbsDj/Yl2/PiJureK46xsNqsWNOpnI4z QIShv83U/GKbPWkvS6Sw80qLYDvgYQXeoFXfo= Date: Tue, 28 Feb 2012 12:01:00 +0000 From: Andrea Crotti User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120217 Thunderbird/10.0.2 MIME-Version: 1.0 To: Tim Chase Subject: Re: check if directory is writable in a portable way References: <4F4CA76B.5040408@gmail.com> <4F4CBBE3.5060108@tim.thechases.com> In-Reply-To: <4F4CBBE3.5060108@tim.thechases.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1330430465 news.xs4all.nl 6912 [2001:888:2000:d::a6]:49098 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20975 On 02/28/2012 11:34 AM, Tim Chase wrote: > 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 > That's really ugly right, didn't think about this possibility. Well it's not a really critical part of my code, so I guess it's fine with the try-except dance.. But isn't there (or should there be) a windows-related library that abstracts this horrible things? Thanks