LoginSignup
2
2

More than 5 years have passed since last update.

ls -R on Google Drive

Posted at
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
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2