Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20979 > unrolled thread
| Started by | Tim Golden <mail@timgolden.me.uk> |
|---|---|
| First post | 2012-02-28 13:33 +0000 |
| Last post | 2012-02-28 13:33 +0000 |
| 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.
Re: check if directory is writable in a portable way Tim Golden <mail@timgolden.me.uk> - 2012-02-28 13:33 +0000
| From | Tim Golden <mail@timgolden.me.uk> |
|---|---|
| Date | 2012-02-28 13:33 +0000 |
| Subject | Re: check if directory is writable in a portable way |
| Message-ID | <mailman.227.1330436089.3037.python-list@python.org> |
On 28/02/2012 12:01, Andrea Crotti wrote:
> 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?
Well I maintain winsys [1] which does help out in admin-y tasks
in general on Windows, but I'm afraid I've never had the need
to scratch this particular itch, and the API solution is messier
than you might think, and more fiddly to get right. If I ever
get enough moments together I might do it, but patches are
always looked upon kindly :)
TJG
[1] https://github.com/tjguk/winsys
Back to top | Article view | comp.lang.python
csiph-web