Ian Propst-Campbell
Ian Propst-Campbell

Reputation: 158

.searchFiles() iterator returns "invalid argument: q" error

I'm trying to write a script that takes the name of a file from a spreadsheet, searches my drive for that file, and returns the Id of that file.

I think it doesn't like my query string, but I'm not sure what's wrong with it.

function SearchDriveFiles (){

var moduleName = 
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet.getRange("F19").getValue();
var searchFor = 'title contains"'+moduleName+'"'; 

 var names =[];
 var fileIds=[];
 var files = DriveApp.searchFiles(searchFor);

 //iterates through files 
while (files.hasNext()) { //This is where the error happens
var file = files.next();
var fileId = file.getId();
fileIds.push(fileId);
var name = file.getName();
names.push(name);}

Logger.log(fileIds);
Logger.log(names);

}

I want to log the file name and Id, but every time I run the function I get "Invalid argument: q"

Upvotes: 3

Views: 979

Answers (1)

Tanaike
Tanaike

Reputation: 201428

How about this modification?

From:

var searchFor = 'title contains"'+moduleName+'"';

To:

var searchFor = 'title contains "'+moduleName+'"';
  • Please insert a space.

References:

If this didn't resolve your issue, I apologize.

Upvotes: 5

Related Questions