xcp_d.utils.filemanip module
Miscellaneous file manipulation functions.
- xcp_d.utils.filemanip.fname_presuffix(fname, prefix='', suffix='', newpath=None, use_ext=True)[source]
Manipulate path and name of input filename.
- Parameters:
fname (string) – A filename (may or may not include path)
prefix (string) – Characters to prepend to the filename
suffix (string) – Characters to append to the filename
newpath (string) – Path to replace the path of the input fname
use_ext (boolean) – If True (default), appends the extension of the original file to the output name.
- Returns:
Absolute path of the modified filename
- Return type:
Examples
>>> from nipype.utils.filemanip import fname_presuffix >>> fname = 'foo.nii.gz' >>> fname_presuffix(fname,'pre','post','/tmp') '/tmp/prefoopost.nii.gz'
>>> from nipype.interfaces.base import Undefined >>> fname_presuffix(fname, 'pre', 'post', Undefined) == fname_presuffix(fname, 'pre', 'post') True
- xcp_d.utils.filemanip.split_filename(fname)[source]
Split a filename into parts: path, base filename and extension.
- Parameters:
fname (
str
) – file or path name- Returns:
Examples
>>> from nipype.utils.filemanip import split_filename >>> pth, fname, ext = split_filename('/home/data/subject.nii.gz') >>> pth '/home/data'
>>> fname 'subject'
>>> ext '.nii.gz'