cfdm.abspath

cfdm.abspath(path, uri=None)[source]

Return a normalised absolute version of a path.

Added in version (cfdm): 1.7.0

Parameters:
path: str

The file or directory path.

uri: None or bool, optional

If True then the returned path will begin with a URI scheme component followed by a : character, such as file://data/file.nc, https://remote/data/file.nc, etc.). If False then the returned path will not begin with a URI scheme component only if the input path does. If None (the default) then the returned path will begin with a URI scheme component if the input path does.

Added in version (cfdm): 1.12.0.0

Returns:
str

The normalised absolutised version of the path.

Examples

>>> import os
>>> os.getcwd()
'/data/archive'
>>> cfdm.abspath("")
'/data/archive'
>>> cfdm.abspath("file.nc")
'/data/archive/file.nc'
>>> cfdm.abspath("../file.nc")
'/data/file.nc'
>>> cfdm.abspath("file:///file.nc")
'file:///file.nc'
>>> cfdm.abspath("file://file.nc")
'file://file.nc/data/archive'
>>> cfdm.abspath("file:/file.nc")
'file:/file.nc'
>>> cfdm.abspath("http:///file.nc")
'http:///file.nc'
>>> cfdm.abspath("http://file.nc")
'http://file.nc'
>>> cfdm.abspath("http:/file.nc")
'http:/file.nc'
>>> cfdm.abspath("file.nc", uri=True)
'file:/data/archive/file.nc'
>>> cfdm.abspath("../file.nc", uri=True)
'file:/data/file.nc'
>>> cfdm.abspath("file:///file.nc", uri=True)
'file:///file.nc'
>>> cfdm.abspath("file://file.nc", uri=True)
'file://file.nc/data/archive'
>>> cfdm.abspath("file:/file.nc", uri=True)
'file:/file.nc'
>>> cfdm.abspath("http:///file.nc", uri=True)
'http:///file.nc'
>>> cfdm.abspath("http://file.nc", uri=True)
'http://file.nc'
>>> cfdm.abspath("http:/file.nc", uri=True)
'http:/file.nc'
>>> cfdm.abspath("file.nc", uri=False)
'/data/archive/file.nc'
>>> cfdm.abspath("../file.nc", uri=False)
'/data/file.nc'
>>> cfdm.abspath("file:///file.nc", uri=False)
'/file.nc'
>>> cfdm.abspath("file://file.nc", uri=False)
'/data/archive'
>>> cfdm.abspath("file:/file.nc", uri=False)
'/file.nc'
 >>> cfdm.abspath("http:///file.nc", uri=False)
ValueError: Can't set uri=False for path='http:///file.nc'