Search code examples
pythondrive

Drive API v3 - Getting all files inside a particular folder


I am trying to list all files inside a folder my-folder.

service.files().list(
q="mimeType ='application/vnd.google-apps.folder' and name='my-folder'"
,**params)`

returns a dictionary like this:

{'files': [{'id': 's0meId', 'name': 'my-folder'}]}

Is there any method I can use to get a list of all files inside this folder?


Solution

  • The mimeType ='application/vnd.google-apps.folder' filter you employed filters the search to return just folders.

    First get the collection id using your existing query.

     collection_id = result['files'][0]['id']
    

    Then use that to formulate another query to fetch files in the collection

    service.files().list(
        q=f"mimeType != 'application/vnd.google-apps.folder' and '{collection_id}' in parents"
        , **params)`