I want to access the names of the files in a particular path. The JavaScript code written separately works fine whereas when it is put inside the HTML, the code doesn't works.
fs = require('fs');
var directory = 'IPIE/';//direcory name(path name)
fs.readdir(directory, (err, files)=> {
for (index in files) {
console.log(files[index]);
}
});
This code gives the output i.e., the folder names as below:
BigBubbles
Edgegap
Sticky
Whereas the html code below doesn't work fine
<html>
<body>
<label>Input Option:</label>
<select id="input_mode"></select>
<button onclick='displayfiles()'>abc</button>
</body>
<script>
function displayfiles() {
var fs = require('fs');
var directory = 'IPIE/'; //folder name
fs.readdir(directory, (err, files) => {
var select = document.getElementById("input_mode");
for (index in files) {
select.options[select.options.length] = new Option(files[index], index);
}
});
}
</script>
</html>
And I noticed after var fs = require('fs'); line, alert("something") doesn't work which means the execution stops at that line..???
Please help
requiredoes not work on a browser. And next, the browser is not allowed to access the file system (thankfully!!).