check if directory is writable in a portable way

Tim Chase python.list at tim.thechases.com
Tue Feb 28 13:12:44 CET 2012


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 limited experiences in the recesses of 
Win32 APIs).

Additionally, even if you did a LBYL instead, you'd open yourself 
to a race-condition where the permissions could theoretically 
change between the time you check and the time you actually try 
to write there.  Granted, that's a slim chance and usually would 
be a "Doctor, my foot hurts when I do $THIS"/"Well don't do that" 
situation where the solution is "don't change the permissions 
while running this program".

-tkc






More information about the Python-list mailing list