cfdm.Data.replace_directory

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

Replace file directories in-place.

Modifies the names of files that are required to deliver the computed data array.

New 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.

common: bool, optional

If True the base directory structure that is common to all files with new.

Returns

None

Examples

>>>
>>> d.get_filenames()
{'/data/file1.nc', '/home/file2.nc'}
>>> d.replace_directory('/data', '/new/data/path/')
>>> d.get_filenames()
{'/new/data/path/file1.nc', '/home/file2.nc'}
>>> d.replace_directory('/new/data, '/archive/location')
>>> d.get_filenames()
{'/archive/location/path/file1.nc', '/home/file2.nc'}
>>> d.replace_directory('/home')
>>> d.get_filenames()
{'/archive/location/path/file1.nc', 'file2.nc'}