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