简体   繁体   中英

Create several folders at once in Google Drive SDK

Is there a better way to create several folder at once in Google drive. I know I could run the createFolder() function three times but this seems to be quite not efficiat?

Right now I'm just running it like so:

createFolder("pen",id,function(){
  createFolder("paper",id,function(){
    createFolder("scripts",id,function(){
        console.log(file)
    })
  })
});

Maybe I'm doing it wrong but basically I'm organizing all generated files in folders and maybe Google Drive intended to do this differently. What you guys/gals thing?

You need to alter the flow similar to what's below:

function createFolders(folders, id, callback) {
  var remaining = folder.length;
  var results = [];
  for (var i = 0; i < remaining; i++) {
    createFolder(folders[i], id, function() {
      remaining--;
      if (remaining == 0) {
        callback && callback();
      }
    });
  } // end of for
}

createFolders(["pen", "paper", "scripts"], id, function() {
  // all jobs executed
});

If you are using the Google APIs JavaScript Client Lib, batch requests are supported: https://developers.google.com/api-client-library/javascript/features/rpcbatch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM