to_abspath#

to_abspath(path: Union[str, cloudpathlib.cloudpath.CloudPath, pathlib.Path], create: bool = True, raise_file_not_found: 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)",
                        type=to_abspath)
Parameters
  • path (Union[str, CloudPath, Path]) – Path as a string (relative or absolute)

  • create (bool) – Create directory if not existing

Returns

Absolute path

Return type

Union[CloudPath, Path]