Search for files and folders

Use the files.list method to search for files and folders.

Search for all files and folders on the current user's My Drive

Use the files.list without any parameters to return all files and folders.

Search for specific files or folders on the current user's My Drive

To search for a specific set of files or folders, use the query string q with files.list to filter the files to return.

This example shows the format of a query string:

query_term operator values


  • query_term is the query term or field to search upon. To view the query terms that can be used to filter shared drives, refer to Search query terms.
  • operator specifies the condition for the query term. To view which operators you can use with each query term, refer to Query operators.
  • values are the specific values you want to use to filter your search results.

For example, the following query string filters the search to just return folders:

q: mimeType = 'application/'

The following example shows how to use a client library to filter search results to file names and IDs of JPEG image files. This example uses the mimeType query term to narrow results to files of type image/jpeg. This example also sets spaces to drive to further narrow the search to the drive space. When nextPageToken returns null, there are no more results.


String pageToken = null;
do {
  FileList result = driveService.files().list()
      .setFields("nextPageToken, files(id, name)")
  for (File file : result.getFiles()) {
    System.out.printf("Found file: %s (%s)\n",
        file.getName(), file.getId());
  pageToken = result.getNextPageToken();
} while (pageToken != null);


from __future__ import print_function

import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

def search_file():
    """Search file in drive location

    Load pre-authorized user credentials from the environment.
    TODO(developer) - See
    for guides on implementing OAuth2 for the application.
    creds, _ = google.auth.default()

        # create gmail api client
        service = build('drive', 'v3', credentials=creds)
        files = []
        page_token = None
        while True:
            # pylint: disable=maybe-no-member
            response = service.files().list(q="mimeType='image/jpeg'",
                                            fields='nextPageToken, '
                                                   'files(id, name)',
            for file in response.get('files', []):
                # Process change
                print(F'Found file: {file.get("name")}, {file.get("id")}')
            files.extend(response.get('files', []))
            page_token = response.get('nextPageToken', None)
            if page_token is None:

    except HttpError as error:
        print(F'An error occurred: {error}')
        files = None

    return files

if __name__ == '__main__':


 * Search file in drive location
 * @return{obj} data file
 * */
async function searchFile() {
  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  // Get credentials and build service
  // TODO (developer) - Use appropriate auth mechanism for your app
  const auth = new GoogleAuth({scopes: ''});
  const service ={version: 'v3', auth});
  const files = [];
  try {
    const res = await service.files.list({
      q: 'mimeType=\'image/jpeg\'',
      fields: 'nextPageToken, files(id, name)',
      spaces: 'drive',
    Array.prototype.push.apply(files, res.files); {
      console.log('Found file:',,;
  } catch (err) {
    // TODO(developer) - Handle error
    throw err;

To restrict the search to folders, use the query string to set the MIME type to q: mimeType = 'application/'

Query string examples

This table shows some basic query strings. The actual code differs depending on the client library you use for your search.

What you want to query Example
Files with the name "hello" name = 'hello'
Files with a name containing the words "hello" and "goodbye" name contains 'hello' and name contains 'goodbye'
Files with a name that does not contain the word "hello" not name contains 'hello'
Folders that are Google apps or have the folder MIME type mimeType = 'application/'
Files that are not folders mimeType != 'application/'
Files that contain the text "important" and in the trash fullText contains 'important' and trashed = true
Files that contain the word "hello" fullText contains 'hello'
Files that do not have the word "hello" not fullText contains 'hello'
Files that contain the exact phrase "hello world" fullText contains '"hello world"'
Files with a query that contains the "\" character (e.g., "\authors") fullText contains '\\authors'
Files with ID within a collection, e.g. parents collection '1234567' in parents
Files in an Application data folder in a collection 'appDataFolder' in parents
Files for which user "" has write permission '' in writers
Files for which members of the group "" have write permission '' in writers
Files modified after a given date modifiedTime > '2012-06-04T12:00:00' // default time zone is UTC
Files shared with the authorized user with "hello" in the name sharedWithMe and name contains 'hello'
Files that have not been shared with anyone or domains (only private, or shared with specific users or groups) visibility = 'limited'
Image or video files modified after a specific date modifiedTime > '2012-06-04T12:00:00' and (mimeType contains 'image/' or mimeType contains 'video/')

Search for files with a custom file property

To search for files with a custom file property, use the appProperties search query term with a key and value. For example, to search for a custom file property called additionalID with a value of 8e8aceg2af2ge72e78:

appProperties has { key='additionalID' and value='8e8aceg2af2ge72e78' }

For further information on custom file properties, see Add custom file properties.

Search the corpora

Searches that call files.list use the user corpus by default. To search other corpora, such as files shared to a Google Workspace domain, use the corpora parameter.

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