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


Groups > comp.lang.python > #21015 > unrolled thread

Re: check if directory is writable in a portable way

Started byMark Hammond <skippy.hammond@gmail.com>
First post2012-02-29 10:32 +1100
Last post2012-02-29 10:32 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: check if directory is writable in a portable way Mark Hammond <skippy.hammond@gmail.com> - 2012-02-29 10:32 +1100

#21015 — Re: check if directory is writable in a portable way

FromMark Hammond <skippy.hammond@gmail.com>
Date2012-02-29 10:32 +1100
SubjectRe: check if directory is writable in a portable way
Message-ID<mailman.270.1330471991.3037.python-list@python.org>
On 28/02/2012 9:07 PM, Andrea Crotti wrote:
> How should I check if I can create files in a directory?

By trying to create them there :)  Presumably you want to know that so 
you can write something "real" - so just write that something real.

The problem gets quite hard when you consider things like elevation - 
your *user* may have rights to write to a directory but only when 
elevated - think writing into Program Files.  Further, this check can 
only ever be transient - what if you have the rights by virtue of a 
group membership, but tomorrow you are no longer in that group?  Or by 
virtue of being the "owner" of the directory but later losing the ownership?

The only reasonable way to check is to write to it, and you may as well 
skip attempting to write a temp file - just write what you care about 
and handle failure in the most graceful way you can.  This is what 
almost every app does - consider apps with a "save as" dialog - they 
never check the directory is writable, they just attempt the actual 
write and handle the failure.

Mark

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web