Google pydrive函数用作操作系统

时间:2019-07-19 13:12:43

标签: python pydrive

我正在尝试使用pydrive创建文件夹树,我正在尝试构建一个返回文件夹ID的小函数,因此上载文件时我的生活变得很轻松,因为我有很多重复的文件夹名需要编写一个函数来返回mainFolder/Google/photos/July而不是mainFolder/Instagram/photos/July的ID July。

我编写了以下函数来帮助

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)

def search_folder(folder_name,folder_id):
    file_list = drive.ListFile({'q': "'%s' in parents and trashed=false" % folder_id}).GetList()
    for folder in file_list:
        if folder['title']==folder_name:
            return folder['id']
    return ''

def get_folder_id_by_name(folder_name):
    folders = drive.ListFile(
                    {'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList()

我要寻找的是一个简单的函数,因此可以按以下方式使用 get_folder_id(root-folder,sub-folder,sub-folder ...)并返回folder ['id']

0 个答案:

没有答案