def project_by_path(window, filename):
    """Returns the project folder which matches the base path of the file."""

    if window is None:
        return None

    projects = window.project_data()

    if type(projects) != dict or projects.get("folders", None) is None:
        return None

    for folder in projects["folders"]:
        if filename.startswith(folder["path"]) \
           and folder.get("remotePath", None) is not None:
            return folder

    return None