OS.MKDIR( ) Overwriting previous folder created...

nirsof at gmail.com nirsof at gmail.com
Fri Feb 3 12:24:40 EST 2006


The corect way is to try os.mkdir, catch the exception and check the
errno value, which tell you why the call failed.

If the directory exists, you can ignore the exception, if its another
error, you usually had to raise it again and let the caller handle it.

Example:
import errno

try:
    os.mkdir(path)
except OSError, err:
    if err.errno != errno.EEXIST:
        raise

Any other way may have race conditions, for example, you check if the
directory exits, and its missing, then another process or thread
creates it before you try to create the missing directory, and your
mkdir call will raise.




More information about the Python-list mailing list