Google Script / JavaScript:Missing)在参数列表之后

时间:2016-08-14 23:25:42

标签: javascript syntax

我正在努力尝试在我们自己的家庭安全项目超过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);

    };

1 个答案:

答案 0 :(得分:1)

你需要逃避你的报价。替换这个:

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

用这个:

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

因为现在,你的String看起来像JS:

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