title: How to get the children count of a folder with Google Drive APIs?
body: <p>I'm using the Google Drive v3 APIs and I'm having some trouble getting the number of elements in a given folder.</p>
  
  <p>Right now I'm using the List API with the following query string:</p>
  
  <blockquote>
    <p>'MyFolderId' in parents</p>
  </blockquote>
  
  <p>Here's the code I'm using (.NET client library):</p>
  
  <pre><code>async Task&lt;int&gt; GetChildrenCountAsync(String folderId)
  {
      FilesResource.ListRequest childrenRequest = Drive.Files.List();
      request.Fields = "files";
      request.Q = $"'{folderId}' in parents  and trashed = false";
      FileList children = await childrenRequest.ExecuteAsync();
      return children?.Files.Count() ?? 0;
  }
  </code></pre>
  
  <p>I'm also using "files" in the "fields" property of the API. This way I get a list of all the files in the folder, I count them and that's it.</p>
  
  <p>The issue though is that this approach is really inefficient - <em>I only want to know the number of children of a folder</em>, nothing else.</p>
  
  <p>Plus, if a folder has too many items, this way I'd have eventually perform multiple queries to retrieve all the results, and I'd waste a considerable amount of data and time.</p>
  
  <p>Is there a way to just <strong>query the number of children of a folder</strong>?</p>
  
  <p>Thank you for your help!</p>