title: Folder structure to json
body: <p>I am trying to take a folder structure and turn it into a JSON with this type of format:</p>
  
  <pre><code>.
  ├── Folder
  │   ├── Image.png
  │   └── Image_1.png
  └── Folder2
      ├── Image.png
      └── Image_1.png
  </code></pre>
  
  <p>With a structure like this:</p>
  
  <pre><code>{
    "Folder": ["Image.png", "Image_1.png"],
    "Folder2": ["Image.png", "Image_1.png"]
  }
  </code></pre>
  
  <p>Thanks. Is something like this possible?</p>
  
  <p>Edit: This is what I have started with but the recursion is breaking when trying to drill down into folders within folders</p>
  
  <pre><code>const fs = require('fs');
  const path = require('path');
  
  var structure = {};
  
  function findFiles(folder) {
      fs.readdir(folder, (err, files) =&gt; {
          files.forEach(file =&gt; {
              console.log(file);
              if(fs.lstatSync(__dirname + "/" + file).isDirectory()){
                  console.log(folder)
                  findFiles(folder + "/" + file);
              }
          });
      })
  }
  
  findFiles(__dirname)
  </code></pre>