Google-Apps-Script exception: Cannot retrieve the next object: iterator has reached the end

前端 未结 1 1727
别跟我提以往
别跟我提以往 2020-12-18 09:02

I\'m trying to write a google app script which lists all folders and files in my google drive. The code below returns - Exception: Cannot retrieve the next object: it

相关标签:
1条回答
  • 2020-12-18 09:47

    I think for some reason, calling next() twice is like looking for another file. So, if there is only one file in the folder, then the next time you call it, in your case looking for the owner it errors out. You had the right idea in the folder loop, change the file loop to this.

    while (files.hasNext()) {  
          var childFile = files.next();
          // Print list of files inside the folder
          Logger.log("--> File Name:  " + childFile.getName());
          Logger.log("--> Owner:  " + childFile.getOwner().getEmail());
        }
    
    0 讨论(0)
提交回复
热议问题