ls -R on Google Drive

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

ls -R on Google Drive
Google Drive file move
Google Drive API Set File Permission (Set permissions on Google Drive files)
Use music21 on Google Colaboratory
Try StyleGAN on Google Colaboratory
Plotly Dash on Google Colab
Mount google drive with google-drive-ocamlfuse
Access Google Drive with Python
Google Drive Api Tips (Python)
Pandas 100 knocks on Google Colaboratory
Script for backing up folders on the server to Google Drive
Display multiple markers on Google Map
Show grass on Google Nest Hub
Download Google Drive files in Python
Use ndb.tasklet on Google App Engine
Run Keras on Google Colaboratory TPU
Play with Turtle on Google Colab
Create and edit spreadsheets in any folder on Google Drive with python