【问题标题】:.searchFiles() iterator returns "invalid argument: q" error.searchFiles() 迭代器返回“无效参数:q”错误
【发布时间】:2019-08-25 09:06:56
【问题描述】:

我正在尝试编写一个脚本,该脚本从电子表格中获取文件名,在我的驱动器中搜索该文件,并返回该文件的 ID。

我认为它不喜欢我的查询字符串,但我不确定它有什么问题。

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);

}

我想记录文件名和 ID,但每次运行该函数时都会收到“无效参数:q”

【问题讨论】:

    标签: google-apps-script google-sheets


    【解决方案1】:

    这个修改怎么样?

    发件人:

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

    收件人:

    var searchFor = 'title contains "'+moduleName+'"';
    
    • 请插入一个空格。

    参考资料:

    如果这没有解决您的问题,我深表歉意。

    【讨论】:

    • 天哪,这确实有效!我添加了空格,函数记录了正确的文件 ID 和名称。非常感谢!
    • @Ian Propst-Campbell 欢迎您。谢谢你让我知道。我很高兴你的问题得到了解决。如果您的问题得到解决,请按接受按钮。与您有相同问题的其他人也可以将您的问题作为可以解决的问题。我认为您的问题和解决方案将对他们有用。如果找不到按钮,请随时告诉我。 stackoverflow.com/help/accepted-answer
    • 好吧,我想我接受了。非常感谢您的帮助!
    • @Ian Propst-Campbell 感谢您的回复。
    猜你喜欢
    • 2021-09-18
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 2021-11-02
    • 2014-04-29
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多