1fs.readdir('./', (err, files) => {
2 files.forEach(file => {
3 // console.log(file);
4})});
1const testFolder = './tests/';
2const fs = require('fs');
3
4fs.readdir(testFolder, (err, files) => {
5 files.forEach(file => {
6 console.log(file);
7 });
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});