フォルダ構造があり、ルート フォルダのフォルダ名とファイル ツリーの下のファイルに基づいて JSON オブジェクトを作成したいと考えています。ファイル名は次のように適切に構成されています。
objectNNN.xyz
NNN は 001、002 などの数字で、xyz は .png、.jpg、.eps、.mp3 のいずれかです。
フォルダー構造は次のようになります (スクリプトへの入力)。
果物
画像
- apple001.jpg
- apple002.jpg
- apple003.jpg
- オレンジ001.jpg
- orange002.png
- オレンジ003.jpg
音
- apple001.mp3
- apple002.mp3
- オレンジ001.mp3
動物
- ...など
食べ物
- ...など
... この FOLDER 構造に基づいて、すべての「セット」(果物、動物など) を読み取り、以下のように各セットの JSON オブジェクトを作成したいと思います: (「単語」キーはすべてから取得されることに注意してください。 images ディレクトリ内のオブジェクト名)。
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