MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / check_parent_dir

Function check_parent_dir

monai/utils/misc.py:629–645  ·  view source on GitHub ↗

Utility to check whether the parent directory of the `path` exists. Args: path: input path to check the parent directory. create_dir: if True, when the parent directory doesn't exist, create the directory, otherwise, raise exception.

(path: PathLike, create_dir: bool = True)

Source from the content-addressed store, hash-verified

627
628
629def check_parent_dir(path: PathLike, create_dir: bool = True) -> None:
630 """
631 Utility to check whether the parent directory of the `path` exists.
632
633 Args:
634 path: input path to check the parent directory.
635 create_dir: if True, when the parent directory doesn't exist, create the directory,
636 otherwise, raise exception.
637
638 """
639 path = Path(path)
640 path_dir = path.parent
641 if not path_dir.exists():
642 if create_dir:
643 path_dir.mkdir(parents=True)
644 else:
645 raise ValueError(f"the directory of specified path does not exist: `{path_dir}`.")
646
647
648def save_obj(

Callers 3

verify_metadataFunction · 0.90
create_sim_dataFunction · 0.90
save_objFunction · 0.85

Calls

no outgoing calls

Tested by 1

create_sim_dataFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…