r"""
    Searches for and finds a path garuenteed to not exist.

    Args:
        path_ (str):  path string. If may include a "%" formatstr.
        dpath (str):  directory path(default = None)
        offset (int): (default = 0)
        suffix (None): (default = None)

    Returns:
        str: path_ - path string

    CommandLine:
        python -m utool.util_path non_existing_path

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> base = ut.ensure_app_resource_dir('utool', 'tmp')
        >>> ut.touch(base + '/tmp.txt')
        >>> ut.touch(base + '/tmp0.txt')
        >>> ut.delete(base + '/tmp1.txt')
        >>> path_ = base + '/tmp.txt'
        >>> newpath = ut.non_existing_path(path_)
        >>> assert basename(newpath) == 'tmp1.txt'

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> base = ut.ensure_app_resource_dir('utool', 'tmp')
        >>> ut.ensurepath(base + '/dir_old')
        >>> ut.ensurepath(base + '/dir_old0')
        >>> ut.ensurepath(base + '/dir_old1')
        >>> ut.delete(base + '/dir_old2')
        >>> path_ = base + '/dir'
        >>> suffix = '_old'
        >>> newpath = ut.non_existing_path(path_, suffix=suffix)
        >>> ut.assert_eq(basename(newpath), 'dir_old2')

def non_existing_path(path_, dpath=None, offset=0, suffix=None,
                            force_fmt=False):
    r"""
    Searches for and finds a path garuenteed to not exist.

    Args:
        path_ (str):  path string. If may include a "%" formatstr.
        dpath (str):  directory path(default = None)
        offset (int): (default = 0)
        suffix (None): (default = None)

    Returns:
        str: path_ - path string

    CommandLine:
        python -m utool.util_path non_existing_path

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> base = ut.ensure_app_resource_dir('utool', 'tmp')
        >>> ut.touch(base + '/tmp.txt')
        >>> ut.touch(base + '/tmp0.txt')
        >>> ut.delete(base + '/tmp1.txt')
        >>> path_ = base + '/tmp.txt'
        >>> newpath = ut.non_existing_path(path_)
        >>> assert basename(newpath) == 'tmp1.txt'

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> base = ut.ensure_app_resource_dir('utool', 'tmp')
        >>> ut.ensurepath(base + '/dir_old')
        >>> ut.ensurepath(base + '/dir_old0')
        >>> ut.ensurepath(base + '/dir_old1')
        >>> ut.delete(base + '/dir_old2')
        >>> path_ = base + '/dir'
        >>> suffix = '_old'
        >>> newpath = ut.non_existing_path(path_, suffix=suffix)
        >>> ut.assert_eq(basename(newpath), 'dir_old2')
    """
    import utool as ut
    from os.path import basename, dirname

    if dpath is None:
        dpath = dirname(path_)
    base_fmtstr = basename(path_)
    if suffix is not None:
        base_fmtstr = ut.augpath(base_fmtstr, suffix)

    if '%' not in base_fmtstr:
        if not force_fmt:
            # If we have don't have to format,
            # then try to use the first choice
            first_choice = join(dpath, base_fmtstr)
            if not exists(first_choice):
                return first_choice
        # otherwise we ensure we can format and we continue
        base_fmtstr = ut.augpath(base_fmtstr, '%d')

    dname_list = ut.glob(dpath, pattern='*', recursive=False, with_files=True,
                         with_dirs=True)
    conflict_set = set(basename(dname) for dname in dname_list)

    newname = ut.get_nonconflicting_string(base_fmtstr, conflict_set,
                                           offset=offset)
    newpath = join(dpath, newname)
    return newpath