cfdm.Field.replace_directory¶
-
Field.
replace_directory
(old=None, new=None, normalise=False, common=False, constructs=True)[source]¶ Replace a file directory in-place.
Every file in old_directory that is referenced by the data is redefined to be in new.
New in version (cfdm): 1.12.0.0
See also
- Parameters
- old:
str
orNone
, 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
orNone
, 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.
- constructs:
bool
, optional If True (the default) then add also the directory to the data of metadata constructs. If False then don’t do this.
- old:
- Returns
Examples
>>> d.get_filenames() {'/data/file1.nc', '/home/file2.nc'} >>> d.replace_directory('/data', '/new/data/path/') '/new/data/path' >>> d.get_filenames() {'/new/data/path/file1.nc', '/home/file2.nc'}