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);
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.
Pricing. All use of the Drive API is available at no additional cost.
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
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With