gpt4 book ai didi

javascript - 谷歌脚本/JavaScript : Missing ) after argument list

转载 作者:行者123 更新时间:2023-11-27 22:38:00 27 4
gpt4 key购买 nike

我目前正在尝试在我自己的家庭安全项目中自动删除超过 30 天的安全视频文件。当我尝试运行脚本时,我在第 67 行得到一个“参数列表后缺少 )”,即

var files = DriveApp.searchFiles(
'modifiedDate < "' + cutOffDateAsString + '" and (name contains 'Driveway' or name contains 'Kitchen' or name contains 'FrontDoor')');

我不太确定我做错了什么,因为我确实遵循了 Google 文档中针对复合子句所述的示例:

modifiedTime > '2012-06-04T12:00:00' and (mimeType contains 'image/' or mimeType contains 'video/') 

我查看了类似的问题,但我不确定它们是否适用于我的问题,所以我决定在这里问我自己的问题。

这是我的脚本供引用:

function getFilesByDate() {
var arrayOfFileIDs = [];

var ThirtyDaysBeforeNow = new Date().getTime()-3600*1000*24*30;
// 30 is the number of days
//(3600 seconds = 1 hour, 1000 milliseconds = 1 second, 24 hours = 1 day and 30 days is the duration you wanted
//needed in yr-month-day format

var cutOffDate = new Date(ThirtyDaysBeforeNow);
var cutOffDateAsString = Utilities.formatDate(cutOffDate, "GMT", "yyyy-MM-dd");
Logger.log(cutOffDateAsString);

var theFileID = "";

//Create an array of file ID's by date criteria
var files = DriveApp.searchFiles(
'modifiedDate < "' + cutOffDateAsString + '" and (name contains 'Driveway' or name contains 'Kitchen' or name contains 'FrontDoor')');
//This is LINE 67

while (files.hasNext()) {
var file = files.next();
theFileID = file.getId();

arrayOfFileIDs.push(theFileID);
Logger.log('theFileID: ' + theFileID);
Logger.log('date last updated: ' + file.getLastUpdated());
}

return arrayOfFileIDs;
Logger.log('arrayOfFileIDs: ' + arrayOfFileIDs);

};

最佳答案

您需要转义引号。替换这个:

'" and (name contains 'Driveway' or name contains 'Kitchen' or name contains 'FrontDoor')'

这样:

'" and (name contains \'Driveway\' or name contains \'Kitchen\' or name contains \'FrontDoor\')'

因为现在,你的字符串对于 JS 来说是这样的:

modifiedTime > "2016-08-15T12:03:54" and (name contains 

关于javascript - 谷歌脚本/JavaScript : Missing ) after argument list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38947512/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com