Search code examples
pythongoogle-drive-api

How to combine query strings in google drive API python


I am using some python code to list all the files in a folder. I also do not want deleted or trashed files to be listed. I know both queries for this but I am unsure about how to combine them

response = service.files().list(q = "'"+str(folderId)+"' in parents").execute()

Is my current method, folderId being the folder that will have its files listed.

I know that the queries for "search in folder" and "not deleted" are:
"'<folderid>' in parents"
"trashed = false"

I have tried combining with ; , and + and cannot find the correct way to combine them online anywhere else. I'm sure it's simple and someone can help me out. Thanks!


Solution

  • You need and operator to combine multiple filters in a query string

    Try this

    query = "parents in '%s' and trashed = false" % folderId
    response = service.files().list(q = query).execute()