to_abspath

Contents

to_abspath#

to_abspath(raw_path: str | CloudPath | Path, create: bool = True, raise_file_not_found: bool = True) CloudPath | Path[source]#

Return the absolute path of the specified path and check if it exists

If not:

  • If it is a file (aka has an extension), it raises an exception

  • If it is a folder, it creates it

To be used with argparse to retrieve the absolute path of a file, like:

Parameters:
  • raw_path (AnyPathStrType) – Path as a string (relative or absolute)

  • create (bool) – Create directory if not existing

Returns:

Absolute path

Return type:

AnyPathType

Example

>>> parser = argparse.ArgumentParser()
>>> # Add config file path key
>>> parser.add_argument(
>>>     "--config",
>>>     help="Config file path (absolute or relative)",
>>> )