node list files in directory
//requiring path and fs modules
const path = require('path');
const fs = require('fs');
//joining path of directory
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(file);
});
});const path = require('path');
const fs = require('fs');
fs.readdir(
path.resolve(__dirname, 'MyFolder'),
(err, files) => {
if (err) throw err;
for (let file of files) {
console.log(file);
}
}
);const path = require('path')
//...
//inside the `for` loop
const stat = fs.lstatSync(path.join(dir, file))
Also in JavaScript:
- if parameter is not number in js
- arrow keys function javascript
- definition destructuring react
- json boolean
- open pdf in new tab javascript
- compare two array javascript
- json file undefined
- how to create react app in vs code
- hide url in discord.js
- push values to state array class react
- remove duplicate objects from array javascript
- moving letters animation javascript
- jquery add multiple classes
- do you need a semicolon in javascript
- javascript slice
- how to make page scroll to the top jsx
- js selection box excel node
- calculate today date javascript
- javascript remove the current tr with click
- JavaScript function that generates all combinations of a string.
- javascript name capitalization
- angular 8 how to iterate json object in view
- random array javascript
- js focus event