JimmyJump
JimmyJump

Reputation: 13

google apps script DriveApp.searchFiles issue

I am trying to perform a search for files newer than 24 hours using the DriveApp.searchFiles Method. Specifically I am using this..

var files = DriveApp.searchFiles('title contains "data*csv" and modifiedDate > "2014-09-12"');

If I do this it works great however I am trying to use a variable for the string following the modifiedDate param.

I am able to set the date string to yesterday's date using this code I found on google. var d = new Date(); d.setDate(d.getDate() - 1); var d = d.toISOString().substring(0, 10);

This string is set and displays correctly when I log it with logger, however when I try to use "d" in my code it does not work, it gives an error. Here is what I tried.

var files = DriveApp.searchFiles('title contains "data*csv" and modifiedDate > "d"');

From what I can tell either the variable is not set within the quotes or the modifiedDate param does not accept variables or the string type is not correct.

Does anyone know a better or more efficient way to find files in google apps script less than 1 day old?

Upvotes: 1

Views: 1128

Answers (1)

Mr.Rebot
Mr.Rebot

Reputation: 6791

Try using this line:

var files = DriveApp.searchFiles('title contains "data*csv" and modifiedDate > "d"');

To:

var files = DriveApp.searchFiles("title contains 'data*csv' and  modifiedDate > '"+finalDate+"'");

In the first line of code you made the machine think that modifiedDate > d, while in the second line you let your variable get its value at then compare it to modifiedDate > '2016-03-13'

Upvotes: 1

Related Questions