mergin/utils.py
def unique_path_name(path):
    """
    Generates an unique name for the given path. If the given path does
    not exist yet it will be returned unchanged, otherwise a sequntial
    number will be added to the path in format:
      - if path is a directory: "folder" -> "folder (1)"
      - if path is a file: "filename.txt" -> "filename (1).txt"

    :param path: path to file or directory
    :type path: str
    :returns: unique path
    :rtype: str
    """
    unique_path = str(path)

    is_dir = os.path.isdir(path)
    head, tail = os.path.split(os.path.normpath(path))
    ext = ''.join(Path(tail).suffixes)
    file_name = tail.replace(ext, '')

    i = 0
    while os.path.exists(unique_path):
        i += 1

        if is_dir:
            unique_path = f"{path} ({i})"
        else:
            unique_path = os.path.join(head, file_name) + f" ({i}){ext}"

    return unique_path

    Generates an unique name for the given path. If the given path does
    not exist yet it will be returned unchanged, otherwise a sequntial
    number will be added to the path in format:
      - if path is a directory: "folder" -> "folder (1)"
      - if path is a file: "filename.txt" -> "filename (1).txt"

    :param path: path to file or directory
    :type path: str
    :returns: unique path
    :rtype: str
    
Generates an unique name for the given path.
Generates an unique name for the given path .
def unique_path_name(path):
    unique_path = str(path)
    is_dir = os.path.isdir(path)
    head, tail = os.path.split(os.path.normpath(path))
    ext = ''.join(Path(tail).suffixes)
    file_name = tail.replace(ext, '')
    i = 0
    while os.path.exists(unique_path):
        i += 1
        if is_dir:
            unique_path = f"{path} ({i})"
        else:
            unique_path = os.path.join(head, file_name) + f" ({i}){ext}"
    return unique_path
def unique_path_name ( path ) : unique_path = str ( path ) is_dir = os . path . isdir ( path ) head , tail = os . path . split ( os . path . normpath ( path ) ) ext = '' . join ( Path ( tail ) . suffixes ) file_name = tail . replace ( ext , '' ) i = 0 while os . path . exists ( unique_path ) : i += 1 if is_dir : unique_path = f"{path} ({i})" else : unique_path = os . path . join ( head , file_name ) + f" ({i}){ext}" return unique_path
Generates an unique name for the given path.
Generates an unique name for the given path .
"""
    Generates an unique name for the given path. If the given path does
    not exist yet it will be returned unchanged, otherwise a sequntial
    number will be added to the path in format:
      - if path is a directory: "folder" -> "folder (1)"
      - if path is a file: "filename.txt" -> "filename (1).txt"

    :param path: path to file or directory
    :type path: str
    :returns: unique path
    :rtype: str
    """
None
str
path
path to file or directory
path to file or directory