cf.NetCDF4Array.replace_directory

NetCDF4Array.replace_directory(old=None, new=None, normalise=False)[source]

Replace the file directory.

Modifies the name of the file.

Added in version (cfdm): 1.12.0.0

Parameters:
old: str or None, optional

The base directory structure to be replaced by new. If None (the default) or an empty string, and normalise is False, then new (if set) is prepended to each file name.

new: str or None, optional

The new directory that replaces the base directory structure identified by old. If None (the default) or an empty string, then old (if set) is replaced with an empty string.

normalise: bool, optional

If True then old and new directories, and the file names, are normalised to absolute paths prior to the replacement. If False (the default) then no normalisation is done.

Returns:
NetCDF4Array

A new NetCDF4Array with modified file locations.

Examples

>>> a.get_filename()
'/data/file1.nc'
>>> b = a.replace_directory('/data', '/new/data/path/')
>>> b.get_filename()
'/new/data/path/file1.nc'
>>> c = b.replace_directory('/new/data', None)
>>> c.get_filename()
'path/file1.nc'
>>> c = b.replace_directory('path', '../new_path', normalise=False)
>>> c.get_filename()
'../new_path/file1.nc'
>>> c = b.replace_directory(None, '/data')
>>> c.get_filename()
'/data/../new_path/file1.nc'
>>> c = b.replace_directory('/new_path/', None, normalise=True)
>>> c.get_filename()
'file1.nc'