-2

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]);
  }
}
TheMaster
  • 45,448
  • 6
  • 62
  • 85
Parsec82
  • 1
  • 1
  • Review Best practices. You should create a array and setValues to a sheet or `getContinuationToken()` to continue later. See [tag info page](https://stackoverflow.com/tags/google-apps-script/info) for more details. – TheMaster Apr 23 '20 at 09:49

1 Answers1

0

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.

user12976477
  • 57
  • 1
  • 7