Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20976
| Date | 2012-02-28 05:34 -0600 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: check if directory is writable in a portable way |
| References | <4F4CA76B.5040408@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.223.1330431047.3037.python-list@python.org> (permalink) |
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
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