import os

def check_path(path):
    """
    Extend the name path to avoid overwriting existing files.

    Parameters
    ----------
    path : str
        Path currently selected
    """
    if os.path.exists(path):
        i=0
        new_path = f"{path}_{i}"
        while os.path.exists(new_path):
            new_path = f"{path}_{i}"
            i+=1
        return new_path
    return path
