title: Create Treeview from S3 Results
body: <p>I am trying to create a treeview from a series of AWS S3 results.  I need to create an array in a specific Key:Value format so that we can use them dynamically in our website.  I have looked at many different solutions, but couldn't find one that solved this problem.  Using Node for this app, so will be using Javascript.  </p>
  
  <p>This has to be dynamic as the depth of the Buckets can vary widely.  </p>
  
  <p><strong>Source Array:</strong></p>
  
  <pre><code>[{  
      Key: "Test Folder/",
  },
  {
      Key: "Test Folder/2nd level folder/",
  },
  {
      Key: "Test Folder/2nd level folder/West-Rockies Flow Summary 191204.pdf",
  },
  {
      Key: "Test Folder/2nd level folder/West-Rockies Flow Summary 191205.pdf",
  },
  {
      Key: "Test Folder/2nd level folder/sub-sub-folder/",
  },
  {
      Key: "Test Folder/2nd level folder/sub-sub-folder/West-Rockies Flow Summary 191120.pdf",
  },
  {
      Key: "Test Folder/2nd level folder/sub-sub-folder/West-Rockies Flow Summary 191121.pdf",
  },
  {
      Key: "Test Folder/West-Rockies Flow Summary 191211.pdf",
  },
  {
      Key: "Test Folder/West-Rockies Flow Summary 191212.pdf",
  },
  {
      Key: "main/",
  },
  {
      Key: "main/test.txt",
  }
  </code></pre>
  
  <p>]</p>
  
  <p><strong>Required Output:</strong></p>
  
  <pre><code>[{
  name: "Test Folder",
  folders : [{
      name : "2nd level folder",
      folders : [{
          name : "sub-sub-folder",
          folders : [],
          files : [{
              Key : "Test Folder/2nd level folder/sub-sub-folder/West-Rockies Flow Summary 191120.pdf"
          },{
              Key : "Test Folder/2nd level folder/sub-sub-folder/West-Rockies Flow Summary 191121.pdf"
          }]
      }],
      files : [{
          Key : "Test Folder/2nd level folder/West-Rockies Flow Summary 191204.pdf"
      }, {
          Key : "Test Folder/2nd level folder/West-Rockies Flow Summary 191205.pdf"
      }]
  }],
  files : [{
      Key : "Test Folder/West-Rockies Flow Summary 191211.pdf"
  }, {
      Key : "Test Folder/West-Rockies Flow Summary 191212.pdf"
  }]
  },
  {
      name : "main",
      folders : [],
      files : [{
          Key : "main/test.txt"
      }]
  }];
  </code></pre>