0

I am using the following function that lists all the folders I got in my Account.

function processGoogleDriveFolders() {
    var arrayAllFolderNames,continuationToken,folders,foldersFromToken,thisFolder;
    arrayAllFolderNames = [];

    folders = DriveApp.getFolders();
    continuationToken = folders.getContinuationToken();
    Utilities.sleep(18000);

    foldersFromToken = DriveApp.continueFolderIterator(continuationToken);
    folders = null;
    while (foldersFromToken.hasNext()) {
          thisFolder = foldersFromToken.next();
          arrayAllFolderNames.push(thisFolder.getName());
    };
    //  return arrayAllFolderNames;
    Logger.log(arrayAllFolderNames);

};    

But trying to return all that information as a return statement to place it in the Memory will make the function to not export annything so swapping the last two lines commeting one of each

return arrayAllFolderNames;
// Logger.log(arrayAllFolderNames);

Will not return anything

2
  • 2
    I have to apologize for my poor English skill. Unfortunately, I cannot understand your current issue from But trying to return all that information as a return statement to place it in the Memory will make the function to not export annything so swapping the last two lines commeting one of each and Will not return anything. Can I ask you about the detail of your current issue and your goal? Commented May 3, 2022 at 8:18
  • I'm don't understand the explanation you provided so this is just a guess, but if you want the results to be logged and the function to return your desired data, just place the Logger.log line right above the return one (and, of course, uncomment both). Commented May 3, 2022 at 8:32

1 Answer 1

1

When I tried your script it returned all the folders I have access to, including the ones shared with me and that makes the list rather long... Btw, I think there is no need to add a sleep() in this function. I suggest the code below to get only the 'My Drive' folders by using DriveApp.getRootFolder().getFolders() instead of DriveApp.getFolders()

My test code goes like this :

function processGoogleDriveFolders() {
  var arrayAllFolderNames,folders,folder;
  arrayAllFolderNames = [];
    folders = DriveApp.getRootFolder().getFolders();
    while (folders.hasNext()) {
      folder = folders.next();
        arrayAllFolderNames.push(folder.getName());
    };
    //  return arrayAllFolderNames;
    Logger.log(JSON.stringify(arrayAllFolderNames));
}; 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.