我從PyDrive文檔中獲得以下代碼,該代碼允許訪問我的Google雲端硬盤中的頂級文件夾。我想訪問它的所有文件夾,子文件夾和文件。我該如何去做這件事(我剛開始使用PyDrive)?使用PyDrive訪問文件夾,子文件夾和子文件(Python)
#!/usr/bin/python
# -*- coding: utf-8 -*-
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication
#Make GoogleDrive instance with Authenticated GoogleAuth instance
drive = GoogleDrive(gauth)
#Google_Drive_Tree =
# Auto-iterate through all files that matches this query
top_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
for file in top_list:
print 'title: %s, id: %s' % (file['title'], file['id'])
print "---------------------------------------------"
#Paginate file lists by specifying number of max results
for file_list in drive.ListFile({'q': 'trashed=true', 'maxResults': 10}):
print 'Received %s files from Files.list()' % len(file_list) # <= 10
for file1 in file_list:
print 'title: %s, id: %s' % (file1['title'], file1['id'])
我已經檢查了以下頁面How to list all files, folders, subfolders and subfiles of a Google drive folder,這似乎是我一直在尋找答案,但代碼是不存在了。
也許需要一些速率限制,雖然也 –