title: Finding out if a folder has a sub folder, and if that sub fold has a sub folder and so on in Docslist
body: <p>I was wondering if it is possible to loop through a folder that contains other folders, and the other folders contain other folders, and so on in a dynamic fashion. I do not know how many sub folders have sub folders and would like to find out a way to check this with out hard coding. It's easy enough to go two levels down, but after that I am stumped on how to deal with the multi-branching and storing it in a way that I can manipulate it later. Any tips? In the end the folder structure will be used to create a dynamic Google site layout.</p>
  
  <p>Here is an example of what I have so far:</p>
  
  <pre><code>function myFunction() {
   //Get the folder
   var topFolders = DocsList.getFolder('TestFolder');
   var lvlOneFolders = topFolders.getFolders();
   var num1Folders = lvlOneFolders.length;
   var someArray = [];
  
   for (var i = 0; i &lt; num1Folders; i++){
  
   someArray[i] = lvlOneFolders[i].getFolders();
    }
  
   Logger.log(someArray);
  
  }
  </code></pre>
  
  <p>Regards,</p>
  
  <p>Shawn </p>
  
  <pre><code>function myFunctionTest() {
    var site = SitesApp.getSite('finance-in-motion.com', 'test-site');
    //Get the folder
    var rootFolder = DocsList.getFolder('TestFolder');
    var rootName = rootFolder.getName();
    var files = rootFolder.getFiles();
    var page;
  
    site.createWebPage(rootName, rootName,"&lt;h1&gt;What evs21&lt;/h1&gt;");
  
    page = site.getChildByName(rootName);
  
    createFiles(page,files);
  
    recursTest(rootFolder);
  
    }
  
  function recursTest (currentFolder){
  
    var curLength=currentFolder.getFolders().length;
  
     for(var i = curLength; i &gt; 0; i --){
  
       var folders = currentFolder.getFolders();
       var parentName = currentFolder.getName();
       var foldername = folders[i-1].getName();
       var files = folders[i-1].getFiles();
       getSiteTest(foldername,parentName,files);
  
       if(folders[i-1].getFolders().length != 0){
         recursTest(folders[i-1]);
       }
     }
  
  
   }
  
   function getSiteTest(title,parent,files) {
  
     var site = SitesApp.getSite('finance-in-motion.com', 'test-site');
  
     var matches = site.search(parent);
  
     var page = matches[0];
  
     var child;
  
     //create the sibling page
     page.createWebPage(title, title,"&lt;h1&gt;What evs21&lt;/h1&gt;");
  
     child = page.getChildByName(title);
  
     createFiles(child,files);
  
    }
  
   function createFiles(page,files){
  
     var name;
  
     if (files.length !=0){
  
        for (i in files){
  
           name = files[i].getName();
           page.createWebPage(name,name,"&lt;h1&gt;What evs21&lt;/h1&gt;"); 
  
     }
  
           }
  
  
   }
  </code></pre>