get_or_create_dir

get_or_create_dir#

tollan.utils.file.get_or_create_dir(dirpath: Path | str, on_exist: Any = None, on_create: Any = None, on_create_context: Any = None) Path[source]#

Ensure dirpath exist.

Parameters:
  • dirpath (pathlib.Path, str) – The path of the directory.

  • on_exist (callable, optional) – If set, called if dirpath exists already.

  • on_create (callable, optional) – If set, called if dirpath is created.

  • on_create_context (context, optional) – The context to enter on create.

Returns:

The created or existing directory path

Return type:

Path