Пример #1
0
def get_file_by_path(drive: GoogleDrive, path:str) -> GoogleDriveFile:
    """Tries to obtain a file from the drive via the given path.

    Args:
      drive: The google drive in question
      path: The path to obtain.
    """
    fname = path.split('/')[-1]
    if len(fname) == 0:
        return drive.get_file('root')
    candidate_list = drive.ListFile({'q': f"title = '{fname}' and trashed = false"}).GetList()
    
    for cand in candidate_list:
        cand_paths = drive.get_paths(cand)
        if _normalize_path(path) in cand_paths:
            return cand
    raise FileNotFoundError(f'Could not find file {path}')