def list_recursively(id, dir="", maxResults=100):
children = []
query_result = drive_service.files().list(
q='"%s" in parents' % id,
maxResults=maxResults
).execute()
while True:
children += query_result['items']
if not 'nextPageToken' in query_result:
break
query_result = drive_service.files().list(
q='"%s" in parents' % id,
pageToken=query_result['nextPageToken'],
maxResults=maxResults
).execute()
result = []
for item in children:
path = "%s/%s" % (dir, item['title'])
result.append((path, item))
if item['mimeType'] == 'application/vnd.google-apps.folder':
result += list_recursively(item['id'], path)
return result
Recommended Posts