xcp_d.utils.filemanip.fname_presuffix

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:

str

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