function - on google drive, does folder exist always returns false -


i using google app scripts create folder on google drive. don't want duplication on drive created function find out if folder exists.

i putting folder names array , seeing if folder name exists in array. returns false though...

can see i've gone wrong here? or there better method of finding out if folder exists on drive or not??

function doescontainerexist(container) {   var folders = driveapp.getfolders();   var folders = new array;   var boolean;    while(folders.hasnext()) {     folders.push(folders.next());   }    if(folders.indexof(container) == -1) {     boolean = false;   } else {     boolean = true;   }   logger.log(container);    return boolean;  }; 

there efficient way check if folder exist, here code testfunction try :

function testtest(){   logger.log(testfolder('photos'));// returns true if folder exists, false if doesn't }  function testfolder(foldername){   var exist = true;   try{var testfolder = docslist.getfolder(foldername)}   catch(err){exist=false}   return exist; } 

since final purpose create folder can create directly inside 'catch' part of script or integrate try/catch in existing code use create folder.


Comments