def rename(in_files, suffix=None):
    """Rename all the files in `in_files` adding the `suffix` keeping its
    extension and basedir."""
    import os.path as path
    from nipype.utils.filemanip import filename_to_list, split_filename, list_to_filename
    out_files = []
    for idx, filename in enumerate(filename_to_list(in_files)):
        base, name, ext = split_filename(filename)
        if suffix is None:
            new_name = name + '_%03d' % idx + ext
        else:
            new_name = name + suffix + ext
        out_files.append(path.join(base, new_name))
    return list_to_filename(out_files)
