Re: check if directory is writable in a portable way

2012-02-28 Thread Mark Hammond
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

Re: check if directory is writable in a portable way

2012-02-28 Thread Tim Golden
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 F

Re: check if directory is writable in a portable way

2012-02-28 Thread Tim Chase
On 02/28/12 06:01, Andrea Crotti wrote: How should I check if I can create files in a directory? But isn't there (or should there be) a windows-related library that abstracts this horrible things? Yes, there should be. There isn't as far as I know (though that doesn't mean much given my limi

Re: check if directory is writable in a portable way

2012-02-28 Thread Tim Chase
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 depe

Re: check if directory is writable in a portable way

2012-02-28 Thread Andrea Crotti
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

Re: check if directory is writable in a portable way

2012-02-28 Thread Tim Golden
On 28/02/2012 10:07, Andrea Crotti wrote: How should I check if I can create files in a directory? I tried to simply check if the directory is writeable with this function: def is_writable(name): """Return true if the file is writable from the current user """ return os.access(name, os.W_OK) b

check if directory is writable in a portable way

2012-02-28 Thread Andrea Crotti
How should I check if I can create files in a directory? I tried to simply check if the directory is writeable with this function: def is_writable(name): """Return true if the file is writable from the current user """ return os.access(name, os.W_OK) but that doesn't work at all on