I have a problem that seems small, but it is no longer making me sleep at night, I am probably thinking about it too much and I have lost sight of the correct path!
I\'m
Unfortunately, reading data from a directory isn't supported in JavaScript. You might need a server side language like PHP or Node JS to read the directory and add them in HTML.
For example, if it's PHP, you can do something like List all files in one directory PHP. You can use that array to build your array:
Or if you're using Node JS, it's still simpler:
const directoryPath = path.join(__dirname, 'Documents');
//passsing directoryPath and callback function
fs.readdir(directoryPath, function (err, files) {
//handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
}
//listing all files using forEach
files.forEach(function (file) {
// Do whatever you want to do with the file
console.log('');
});
});
Ultimately you need a server side language for this.