Using Google Apps Script (GAS), I wrote a program that checks the (parent) folder, and finds all files in it that were uploaded within the past 30 minutes. I am using recursion for this as I don't know how many folders exist in that parent folder and how deep each, and I have to detect all files in there.
var arrRecentFiles = [];
var now = new Date();
function FindRecentlyUploadedFiles(pFolder)
{
var cFolders = pFolder.getFolders();
while(cFolders.hasNext())
{
var cFolder = cFolders.next();
var cFiles = cFolder.getFiles();
while(cFiles.hasNext())
{
var cFile = cFiles.next();
//Push only if the file was uploaded within the past 30 minutes
if( CheckIfRecent(cFile) )
{
arrRecentFiles.push(cfile.getName());
}
}
//Recursion here
FindRecentlyUploadedFiles(cFolder);
}
}
/*Check if this cFile was uploaded within the past 30 minutes */
function CheckIfRecent(cFile)
{
var diff = (now.getTime() - cFile.getDateCreated().getTime()) / (60 * 1000);
if(diff < 30)
return true;
else
return false;
}
This program runs fine, but when there are many folders, of course it takes time. I wanted to make this faster, but is this possible at all? I tried without recursion, but it just made the code longer and uglier, so I thought I would stick with recursion. But I am not sure if that is the main cause that is slowing the whole process down.