Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 299
Read Mark Avatar asked Apr 18 '13 07:04

Read Mark


People also ask

How do I get a list of files in Google Drive?

Create a new Google Sheets spreadsheet or open an existing spreadsheet where you want the list saved. Here's a tip: You can quickly create a new Google Sheets spreadsheet using https://spreadsheet.new. Create a sheet in the spreadsheet called "Files". The list of files will be written to the sheet.

Is Google Drive API free?

Pricing. All use of the Drive API is available at no additional cost.


2 Answers

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

like image 64
Burcu Dogan Avatar answered Oct 09 '22 17:10

Burcu Dogan


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();
like image 35
Pir Fahim Shah Avatar answered Oct 09 '22 18:10

Pir Fahim Shah