Search Google Drive using multiple parameters

Viewed 1151

I'm trying to look for the files that are spreadsheets (via mimeType) with the name "Speed", using nameContains or fullTextContains.

If only I put fullTextContains or name contains or any other method it works, but if I combine it with the method mimeType, I get all spreadsheet files and not just the specific matches.

My current script:

function SearchFiles() {
  var searchFor = { 'name contains': "Vel", 'mimeType': "spreadsheet" };
  var names = [];
  var fileIds = [];
  var files = DriveApp.searchFiles(searchFor);
  while (files.hasNext()) {
    var file = files.next();
    var fileId = file.getId();
    fileIds.push(fileId);
    var name = file.getName();
    names.push(name);
  ...
1 Answers

You are getting implicit object->String conversion, because the DriveApp.searchFiles method takes a String parameter, not an Object. Consider instead building an explicit and valid query string that conforms to the expected syntax.

An example:

var qs = "name contains 'Vel' and mimeType='" + MimeType.GOOGLE_SHEETS + "'";
var results = DriveApp.searchFiles(qs);
Related