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 getAllFromDir = source =>
2 fs.readdirSync(source).map(name => path.join(source, name));
3 console.log(getDirectories("C:/"));