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
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());
}