diff --git a/src/ifcopenshell-python/ifcopenshell/file.py b/src/ifcopenshell-python/ifcopenshell/file.py index 6e7d32e308..855b32a9b9 100644 --- a/src/ifcopenshell-python/ifcopenshell/file.py +++ b/src/ifcopenshell-python/ifcopenshell/file.py @@ -462,6 +462,7 @@ class file(object): >>> model.write("path/to/model.anyextension", format=".ifcXML") """ path = Path(path) + path.parent.mkdir(parents=True, exist_ok=True) if format == None: format = ifcopenshell.util.file.guess_format(path) if format == ".ifcXML": diff --git a/src/ifcopenshell-python/test/test_write.py b/src/ifcopenshell-python/test/test_write.py index 0255305140..5ed2d69f19 100644 --- a/src/ifcopenshell-python/test/test_write.py +++ b/src/ifcopenshell-python/test/test_write.py @@ -61,3 +61,6 @@ class TestWrite: def test_write_anyextension_ifczip_ifcxml_format(self): self.assert_model_is_written("model.anyextension", format=".ifcXML", zipped=True) + + def test_write_to_non_existing_dir(self): + self.assert_model_is_written("tmp/model.ifczip")