OS.MKDIR( ) Overwriting previous folder created...
Jeffrey Schwab
jeff at schwabcenter.com
Thu Feb 2 20:43:53 EST 2006
Ernesto wrote:
> I couldn't find this with a search, but isn't there a way to overwrite
> a previous folder (or at least not perform osmkdir( ) if your program
> detects it already exists). Thanks !
Would something like this help?
import os
def failsafe_mkdir(dirname):
try: os.mkdir(dirname)
except: return False
else: return True
if __name__ == "__main__":
dirname = 'adir'
if failsafe_mkdir(dirname):
print "ok\n"
else:
print "couldn't create %s\n" % dirname
More information about the Python-list
mailing list