I am working with Google Drive v3 and I am trying to get all files which are related to following categories:
- files which are not Google Documents (mime type doesn't start from "application/vnd.google-apps."), for example "text/plain", "image/bmp" etc.
- Google Spreadsheets (mime type is "application/vnd.google-apps.spreadsheet")
I want get all these files with single request.
Files from first category can be get with following sub-query:
not mimeType contains 'application/vnd.google-apps.'
Sub-query for second category: mimeType = 'application/vnd.google-apps.spreadsheet'
As result I unite these parts with or
operator and then with query for parent folder id:
'<parentId>' in parents and (mimeType = 'application/vnd.google-apps.spreadsheet' or not mimeType contains 'application/vnd.google-apps.')
But it doesn't work. It returns only Google Spreadsheet files. I tried to execute queries for both file categories separately and they work fine:
'<parentId>' in parents and (mimeType = 'application/vnd.google-apps.spreadsheet')
returns all Google Spreadsheets
and
'<parentId>' in parents and (not mimeType contains 'application/vnd.google-apps.')
returns all not-Google Drive formats.
`
As experiment I checked another cases (a bit simplified):
mimeType = 'application/vnd.google-apps.spreadsheet' or mimeType = 'text/plain'
- returns spreadsheets+texts, correctmimeType = 'application/vnd.google-apps.spreadsheet' or mimeType contains 'text/plain'
- returns spreadsheets only, incorrectmimeType = 'application/vnd.google-apps.spreadsheet' or not mimeType = 'text/plain'
- returns spreadsheets only, incorrect (I have images in the folder also)mimeType contains 'text/plain'
- returns texts, correct
Part of my code for files requesting (with parentId replaced, of course):
Drive.Files.List filesRequest = service
.files()
.list()
.setFields("files(id, name)")
.setQ("'<parentId>' in parents " +
"and (mimeType = 'application/vnd.google-apps.spreadsheet' " +
"or not mimeType contains 'application/vnd.google-apps.')");
FileList result = filesRequest.execute();
List<File> files = result.getFiles();
Used dependencies versions: google-api-services-drive from v3-rev162-1.23.0 to v3-rev173-1.25.0, JDK 1.8.0-91.
Please help.