from pathlib import Path


def deconflict_file(filename):
    """
    Deconflict w/ specified file, if necessary, by extending the name.
    
    Args:
        filename (str)
            File to deconflict with.
        
    Returns:
        new_file (str)
            Path and name of deconflicted file.
    """
    filename = Path(filename)
    if not filename.exists():
        filename.touch()
        return filename.resolve().as_posix()
    else:
        ii = 0
        while filename.with_name('{0}_{1}{2}'.format(filename.stem, ii, filename.suffix)).exists():
            ii += 1
        return filename.with_name('{0}_{1}{2}'.format(filename.stem, ii, filename.suffix)).resolve().as_posix()