Google Apps Script - MAX EXECUTION TIME

68 Views Asked by At

I'm on GSuite Business and i have made a Google Apps Script for read the content on a GDrive folder and write on Column A the name of the file and on Column B the GDrive Link of the file. I have about 8800 Files on this folder and i go over the 30 minutes execution time quota. at this time i don't have idea to solve this problem.. I past here my script...

This script are useful for see the list of images of the product for sync with my ecommerce.

function ImageDatabaseUpdate() {

  //read file on my drive foldeer -> 06 - usato fine serie
  var foldername = '06 - Usato e Fine serie';
  var folderlisting = 'Database GTLG ';

  var folders = DriveApp.getFoldersByName(foldername)
  var folder = folders.next();
  var contents = folder.getFiles();
  var contents = folder.getFiles();

  //Set file id and sheet Immagini
  var ss = SpreadsheetApp.openById("1ok2tfpLFRHE6I4ehR9lfsLwtFy1UfTdJqbi-NCqGVS0");
  var sheet = ss.getSheetByName('immagini');

  //Write heading on first sheet row
  sheet.appendRow(['name','link']);

  var file;
  var name;
  var link;
  var row; 

  //start reading and writing
  while(contents.hasNext()){
    file = contents.next();
    name = file.getName();
    link = file.getUrl();
    sheet.appendRow([name, link]);
  }
}
1

There are 1 best solutions below

1
user12976477 On

Your code goes into an infinite loop because you need contents.next() to move to the next file. Since the folderIterator doesn't increment, while(contents.hasNext()) will continue forever.