Read Mark
Read Mark

Reputation: 683

use google drive api get children without trash

How can I get a folder's children files without the deleted files in trash, my code as follow:

 Children children = service.children();
 Drive.Children.List request = children.list("root");
  do
  {
    try
       {
          ChildList cList = request.execute();
          for (ChildReference cr : cList.getItems())
           {
              File file = service.files().get(cr.getId())   .execute();
              System.out.println(file.getTitle() + "--"+ file.getMimeType());
           }
        request.setPageToken(cList.getNextPageToken());
       }
   catch (IOException e)
      {
          System.out.println("An error occurred: " + e);
          request.setPageToken(null);
      }
 } while (request.getPageToken() != null && request.getPageToken().length() > 0);

Upvotes: 14

Views: 7822

Answers (2)

Pir Fahim Shah
Pir Fahim Shah

Reputation: 10623

If you have a query with multiple conditions, like you want to get ROOT's files and folder, and also don't want to get the trashed files. Then below query will helpful "'root' in parents and trashed=false"

  request.setQ("'root' in parents and trashed=false").execute();

Upvotes: 15

Burcu Dogan
Burcu Dogan

Reputation: 9213

Use trashed = false query when listing:

drive.files().list().setQ("trashed = false").execute();

More querying options are on https://developers.google.com/drive/search-parameters

Upvotes: 32

Related Questions