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

>>> 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]