Files: list

Lists the user's files. Try it now or see an example.

This method accepts the q parameter, which is a search query combining one or more search terms. For more information, see the Search for Files and Team Drives guide.


HTTP request



Parameter name Value Description
Optional query parameters
corpora string Comma-separated list of bodies of items (files/documents) to which the query applies. Supported bodies are 'default', 'domain', 'teamDrive' and 'allTeamDrives'. 'allTeamDrives' must be combined with 'default'; all other values must be used in isolation. Prefer 'default' or 'teamDrive' to 'allTeamDrives' for efficiency.
corpus string The body of items (files/documents) to which the query applies. Deprecated: use 'corpora' instead.

Acceptable values are:
  • "DEFAULT": The items that the user has accessed.
  • "DOMAIN": Items shared to the user's domain.
includeTeamDriveItems boolean Whether Team Drive items should be included in results. (Default: false)
maxResults integer The maximum number of files to return per page. Partial or empty result pages are possible even before the end of the files list has been reached.
orderBy string A comma-separated list of sort keys. Valid keys are 'createdDate', 'folder', 'lastViewedByMeDate', 'modifiedByMeDate', 'modifiedDate', 'quotaBytesUsed', 'recency', 'sharedWithMeDate', 'starred', 'title', and 'title_natural'. Each key sorts ascending by default, but may be reversed with the 'desc' modifier. Example usage: ?orderBy=folder,modifiedDate desc,title. Please note that there is a current limitation for users with approximately one million files in which the requested sort order is ignored.
pageToken string Page token for files.
projection string This parameter is deprecated and has no function.

Acceptable values are:
  • "BASIC": Deprecated
  • "FULL": Deprecated
q string Query string for searching files. See the "Search for Files and Team Drives" guide for the supported syntax.
spaces string A comma-separated list of spaces to query. Supported values are 'drive', 'appDataFolder' and 'photos'.
supportsTeamDrives boolean Whether the requesting application supports Team Drives. (Default: false)
teamDriveId string ID of Team Drive to search.

Request body

Do not supply a request body with this method.


If successful, this method returns a response body with the following structure:

  "kind": "drive#fileList",
  "etag": etag,
  "selfLink": string,
  "nextPageToken": string,
  "nextLink": string,
  "incompleteSearch": boolean,
  "items": [
    files Resource
Property name Value Description Notes
kind string This is always drive#fileList.
etag etag The ETag of the list.
nextPageToken string The page token for the next page of files. This will be absent if the end of the files list has been reached. If the token is rejected for any reason, it should be discarded, and pagination should be restarted from the first page of results.
items[] list The list of files. If nextPageToken is populated, then this list may be incomplete and an additional page of results should be fetched.
incompleteSearch boolean Whether the search process was incomplete. If true, then some search results may be missing, since all documents were not searched. This may occur when searching multiple Team Drives with the "default,allTeamDrives" corpora, but all corpora could not be searched. When this happens, it is suggested that clients narrow their query by choosing a different corpus such as "default" or "teamDrive".


Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).


Uses the Java client library.


import java.util.ArrayList;
import java.util.List;

// ...

public class MyClass {

  // ...

   * Retrieve a list of File resources.
   * @param service Drive API service instance.
   * @return List of File resources.
  private static List<File> retrieveAllFiles(Drive service) throws IOException {
    List<File> result = new ArrayList<File>();
    Files.List request = service.files().list();

    do {
      try {
        FileList files = request.execute();

      } catch (IOException e) {
        System.out.println("An error occurred: " + e);
    } while (request.getPageToken() != null &&
             request.getPageToken().length() > 0);

    return result;

  // ...



Uses the .NET client library.

using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;

using System.Collections.Generic;
// ...

public class MyClass {

  // ...

  /// <summary>
  /// Retrieve a list of File resources.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <returns>List of File resources.</returns>
  public static List<File> retrieveAllFiles(DriveService service) {
    List<File> result = new List<File>();
    FilesResource.ListRequest request = service.Files.List();

    do {
      try {
        FileList files = request.Execute();

        request.PageToken = files.NextPageToken;
      } catch (Exception e) {
        Console.WriteLine("An error occurred: " + e.Message);
        request.PageToken = null;
    } while (!String.IsNullOrEmpty(request.PageToken));
    return result;

  // ...


Uses the PHP client library.

 * Retrieve a list of File resources.
 * @param Google_Service_Drive $service Drive API service instance.
 * @return Array List of Google_Service_Drive_DriveFile resources.
function retrieveAllFiles($service) {
  $result = array();
  $pageToken = NULL;

  do {
    try {
      $parameters = array();
      if ($pageToken) {
        $parameters['pageToken'] = $pageToken;
      $files = $service->files->listFiles($parameters);

      $result = array_merge($result, $files->getItems());
      $pageToken = $files->getNextPageToken();
    } catch (Exception $e) {
      print "An error occurred: " . $e->getMessage();
      $pageToken = NULL;
  } while ($pageToken);
  return $result;


Uses the Python client library.

from apiclient import errors
# ...

def retrieve_all_files(service):
  """Retrieve a list of File resources.

    service: Drive API service instance.
    List of File resources.
  result = []
  page_token = None
  while True:
      param = {}
      if page_token:
        param['pageToken'] = page_token
      files = service.files().list(**param).execute()

      page_token = files.get('nextPageToken')
      if not page_token:
    except errors.HttpError, error:
      print 'An error occurred: %s' % error
  return result


Uses the JavaScript client library.

 * Retrieve a list of File resources.
 * @param {Function} callback Function to call when the request is complete.
function retrieveAllFiles(callback) {
  var retrievePageOfFiles = function(request, result) {
    request.execute(function(resp) {
      result = result.concat(resp.items);
      var nextPageToken = resp.nextPageToken;
      if (nextPageToken) {
        request ={
          'pageToken': nextPageToken
        retrievePageOfFiles(request, result);
      } else {
  var initialRequest =;
  retrievePageOfFiles(initialRequest, []);


Uses the Go client library.

import (

// AllFiles fetches and displays all files
func AllFiles(d *drive.Service) ([]*drive.File, error) {
  var fs []*drive.File
  pageToken := ""
  for {
    q := d.Files.List()
    // If we have a pageToken set, apply it to the query
    if pageToken != "" {
      q = q.PageToken(pageToken)
    r, err := q.Do()
    if err != nil {
      fmt.Printf("An error occurred: %v\n", err)
      return fs, err
    fs = append(fs, r.Items...)
    pageToken = r.NextPageToken
    if pageToken == "" {
  return fs, nil


Uses the Objective-C client library.

#import "GTLDrive.h"
// ...

+ (void)retrieveAllFilesWithService:(GTLServiceDrive *)service
                    completionBlock:(void (^)(NSArray *, NSError *))completionBlock {
  // The service can be set to automatically fetch all pages of the result. More information
  // can be found on <a href=""></a>.
  service.shouldFetchNextPages = YES;

  GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket, GTLDriveFileList *files,
                            NSError *error) {
          if (error == nil) {
            completionBlock(files.items, nil);
          } else {
            NSLog(@"An error occurred: %@", error);
            completionBlock(nil, error);

// ...

Try it!

Use the APIs Explorer below to call this method on live data and see the response.

Send feedback about...

Drive REST API v2
Drive REST API v2
Need help? Visit our support page.