I have access to a network folder where new subfolders are generated daily. In every subfolder theres one json file containing metadata. I was able to access the main folder but not the subfolders. Or at least im able to access the subfolder but only when i give the direct path to it. There starts the problem. Because every day there are new folders i'm only able to access them manually through changing the code. I tried out
var { readdir } = require('fs/promises');
var path1 = "somepath"
async function main() {
try {
const files = await readdir(path1);
for (const file of files)
console.log(file);
} catch (err) {
console.error(err);
}
}
main();
to get a list of the directories. I also tried out
const fs = require('fs');
const path = require('path')
const jsonsInDir = fs.readdirSync('examplepath').filter(file => path.extname(file) === '.json');
jsonsInDir.forEach(file => {
const fileData = fs.readFileSync(path.join('examplepath', file));
const json = JSON.parse(fileData.toString());
console.log(json);
});
To access the files but obviously it wont run through the sub directories. Maybe the answer is pretty obvious but im a newbie to this stuff.