Reputation: 683
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
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
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