check if a directory is already created python -


a basic question, have module creates directories on fly, however, want put more 1 file in dir. if happens, python rises exception , says dir created, how can avoid , check if dir created or not?

the save module looks this:

def createdirs(realiz): # create necessary directories                                                                            path = "./doubdifferences_probandamp_realiz%d/"%realiz os.mkdir(path,0755) directory = os.path.split(path)[0] return directory 

on main program, have this:

for realiz in range(1,1000):     in range(dim):         j in range(i+1,i+4):             ...             dirspaths = mod_savefile.createdirs(realiz) 

you go try except:

try:     os.mkdir(path,0755) except oserror:     pass  

“easier ask forgiveness permission !”

also method more safe testing directory before doing mkdir. indeed, possible between 2 os call implied ispath , mkdir directory may have been created or destroyed thread.


Comments

Popular posts from this blog

c# - OpenXML hanging while writing elements -

php - regexp cyrillic filename not matches -

sql - Select Query has unexpected multiple records (MS Access) -