Folder sharing does not work on Google Shared Drive, so I am trying to automate sharing through Google Apps Script.
I tried to write code with reference to several examples, but I kept getting errors and asked questions.
I got an error saying:
'Cannot retrieve the next object: iterator has reached the end', and I confirmed that sharing of some files was not set.
Below is the code I wrote. How can I fix this problem?
function myFunction() {
var folderid = ""
var folder = DriveApp.getFolderById(folderid);
var files = folder.getFiles();
while (files.hasNext()) {
Logger.log(files.next().getName());
files.next().setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
}
}