to_abspath(path: Union[str, cloudpathlib.cloudpath.CloudPath, pathlib.Path], create: bool = True) Union[cloudpathlib.cloudpath.CloudPath, pathlib.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:

>>> parser = argparse.ArgumentParser()
>>> # Add config file path key
>>> parser.add_argument("--config",
                        help="Config file path (absolute or relative)",
  • path (Union[str, CloudPath, Path]) – Path as a string (relative or absolute)

  • create (bool) – Create directory if not existing


Absolute path

Return type

Union[CloudPath, Path]