Skip to content

Commit 231fcb6

Browse files
authored
Mkdir to always allow parents and exist ok (#2914)
1 parent d10e128 commit 231fcb6

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎openmc/model/model.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def export_to_xml(self, directory='.', remove_surfs=False):
449449
# Create directory if required
450450
d = Path(directory)
451451
if not d.is_dir():
452-
d.mkdir(parents=True)
452+
d.mkdir(parents=True, exist_ok=True)
453453

454454
self.settings.export_to_xml(d)
455455
self.geometry.export_to_xml(d, remove_surfs=remove_surfs)
@@ -490,14 +490,14 @@ def export_to_model_xml(self, path='model.xml', remove_surfs=False):
490490
# exist, create it and place a 'model.xml' file there.
491491
if not str(xml_path).endswith('.xml'):
492492
if not xml_path.exists():
493-
os.mkdir(xml_path)
493+
xml_path.mkdir(parents=True, exist_ok=True)
494494
elif not xml_path.is_dir():
495495
raise FileExistsError(f"File exists and is not a directory: '{xml_path}'")
496496
xml_path /= 'model.xml'
497497
# if this is an XML file location and the file's parent directory does
498498
# not exist, create it before continuing
499499
elif not xml_path.parent.exists():
500-
os.mkdir(xml_path.parent)
500+
xml_path.parent.mkdir(parents=True, exist_ok=True)
501501

502502
if remove_surfs:
503503
warnings.warn("remove_surfs kwarg will be deprecated soon, please "

0 commit comments

Comments
 (0)