cf.relpath

cf.relpath(filename, start=None)[source]

Return a relative filepath to a file.

The filepath is relative either from the current directory or from an optional start point.

If a string containing URL is provided then it is returned unchanged.

Parameters
filename: str

The name of the file.

start: str, optional

The start point for the relative path. By default the current directory is used.

Returns
str

The relative path.

Examples

>>> cf.relpath('/data/archive/file.nc')
'../file.nc'
>>> cf.relpath('/data/archive///file.nc', start='/data')
'archive/file.nc'
>>> cf.relpath('http://data/archive/file.nc')
'http://data/archive/file.nc'