Search for Files and Team Drives

You can search for files with the files.list
method of the Drive API. Domain administrators may also search for all Team
Drives in the organization by setting the useDomainAdminAccess parameter with
the teamdrives.list method.

Both methods accept the q parameter which is a search query
combining one or more search clauses. Each search clause is made up of three parts.

Field

Attribute of the file that is searched, e.g., the
attribute name of the file.

Operator

Test that is performed on the data to provide a match, e.g., contains.

Value

The content of the attribute that is tested, e.g. the name of the file My cool document.

Combine clauses with the conjunctions and or or, and negate the query with
not.

The visibility level of the file. Valid values are anyoneCanFind, anyoneWithLink, domainCanFind, domainWithLink, and limited.

[1] The contains operator only performs prefix matching for a name.
For example, the name "HelloWorld" would match for name contains 'Hello' but not
name contains 'World'.[2] The contains operator only performs matching on entire string tokens for fullText.
For example, if the full text of a doc contains the string "HelloWorld" only the query fullText contains 'HelloWorld' returns a result.
Queries such as fullText contains 'Hello' do not return results in this scenario.[2] The contains operator matches on an exact alphanumeric phrase if it is surrounded by double quotes. For example, if the fullText of a doc contains the string "Hello there world", then the query fullText contains '"Hello there"' will return a result, but the query fullText contains '"Hello world"' will not. Furthermore, since the search is alphanumeric, if the fullText of a doc contains the string "Hello_world", then the query fullText contains '"Hello world"' will return a result.
[3] Fields of type date are not currently comparable to each other, only to constant dates.[4] Role searches do not return content from Team Drives

This search returns all files with an image or video MIME type that were last modified after
June 4, 2012. Because and and or operators are evaluated from left to right, without
parentheses the above example would return only images modified after June 4, 2012,
but would return all videos, even those before June 4, 2012.

Examples

All examples on this page show the unencoded q parameter, where name = 'hello' is encoded as
name+%3d+%27hello%27. Client libraries handle this encoding automatically.

Examples for files.list

Search for files with the name "hello"

name = 'hello'

Search for folders using the folder-specific MIME type

mimeType = 'application/vnd.google-apps.folder'

Search for files that are not folders

mimeType != 'application/vnd.google-apps.folder'

Search for files with a name containing the words "hello" and "goodbye"

name contains 'hello' and name contains 'goodbye'

Search for files with a name that does not contain the word "hello"

not name contains 'hello'

Search for files containing the word "hello" in the content

fullText contains 'hello'

Search for files not containing the word "hello" in the content

not fullText contains 'hello'

Search for files containing the exact phrase "hello world" in the content

fullText contains '"hello world"'
fullText contains '"hello_world"'

Search for files with a query containing the "\" character (e.g., "\authors")

fullText contains '\\authors'

Search for files writeable by the user "test@example.org"

'test@example.org' in writers

Search for files writeable by the members of the group "group@example.org"

'group@example.org' in writers

Search for the ID 1234567 in the parents collection. This finds all files and folders
located directly in the folder whose ID is 1234567.

'1234567' in parents

Search for the alias ID appDataFolder in the parents collection. This finds all files and folders
located directly under the Application Data folder.

'appDataFolder' in parents

Search for files writeable by the users "test@example.org" and
"test2@example.org"

'test@example.org' in writers and 'test2@example.org' in writers

Search for files containing the text "important" which are in the trash

Search for files that have not been shared with anyone or domains (only private, or shared with specific users or groups)

visibility = 'limited'

Examples for teamdrives.list

Search for Team Drives with no assigned organizer

organizerCount = 0

Search for Team Drives created after June 1, 2017

createdTime > '2017-06-01T12:00:00'

Search for Team Drives with the word 'confidential' in the title and 20 or more
members

name contains 'confidential' and memberCount >= 20

Using corpora

Searches are also affected by the corpora selected when calling files.list.
If unspecified, the user corpus is used.
To search other corpora, such as files shared to a G Suite domain or Team Drives,
use the corpora parameter.

Multiple corpora and Team Drives may be searched in a single query, though
incomplete results may be returned if the combined corpus is too large. If the
incompleteSearch field in the result is true, not all documents have been
searched.