1const testFolder = './tests/';
2const fs = require('fs');
3
4fs.readdir(testFolder, (err, files) => {
5 files.forEach(file => {
6 console.log(file);
7 });
8});
9
1const fs = require('fs')
2
3const dir = '/Users/flavio/folder'
4const files = fs.readdirSync(dir)
5
6for (const file of files) {
7 console.log(file)
8}
9
1
2//requiring path and fs modules
3const path = require('path');
4const fs = require('fs');
5//joining path of directory
6const directoryPath = path.join(__dirname, 'Documents');
7//passsing directoryPath and callback function
8fs.readdir(directoryPath, function (err, files) {
9 //handling error
10 if (err) {
11 return console.log('Unable to scan directory: ' + err);
12 }
13 //listing all files using forEach
14 files.forEach(function (file) {
15 // Do whatever you want to do with the file
16 console.log(file);
17 });
18});
1const path = require('path')
2
3//...
4
5//inside the `for` loop
6const stat = fs.lstatSync(path.join(dir, file))
7