forked from SCAICT/website-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist-img.js
More file actions
29 lines (23 loc) · 780 Bytes
/
list-img.js
File metadata and controls
29 lines (23 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fs = require('fs');
const path = require('path');
const imgFolder = './converted/img';
const jsonFilePath = 'images.json';
function readFilesInFolder(folderPath) {
return fs.readdirSync(folderPath).filter(item => {
const itemPath = path.join(folderPath, item);
return fs.statSync(itemPath).isDirectory();
});
}
function createJson() {
const imageFolders = readFilesInFolder(imgFolder);
const imageJson = {};
imageFolders.forEach(folder => {
const folderPath = path.join(imgFolder, folder);
const images = fs.readdirSync(folderPath);
imageJson[folder] = images;
});
const jsonString = JSON.stringify(imageJson, null, 2);
fs.writeFileSync(jsonFilePath, jsonString);
console.log('images.json created successfully.');
}
createJson();