I have folder structure and I would like to create JSON objects based on the folder names in the root folder and the files below in the file tree. The file names are well structured like this:
objectNNN.xyz
Where NNN is a number like 001, 002 ... and xyz could be .png, .jpg, .eps or .mp3
the folder structure is like this (input to the script):
fruits
images
- apple001.jpg
- apple002.jpg
- apple003.jpg
- orange001.jpg
- orange002.png
- orange003.jpg
sounds
- apple001.mp3
- apple002.mp3
- orange001.mp3
animals
- ... etc
foods
- ... etc
... based on this FOLDER structure, I'd like to read all the "sets" (fruits, animals, etc) and create a JSON object for each set like below: (note that the "word" key is take from all the object names in the images directory).
sets = {
animals: [ // this is from the folder name in the root folder
{
word: "cat", // this is from the filename in the images directory eg cat001.jpg
images: [
{
path: "images/basic/cat001.jpg"
}, {
path: "images/basic/cat002.jpg"
}
],
sounds: [ // based on all the images look for sounds
{
path: "sounds/basic/cat001.mp3"
}, {
path: "sounds/basic/cat002.mp3"
}
]
}, // etc more sets and words