1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| var fs = require('fs'); var path = require('path'); function readFileList(dir, filesList = []) { const files = fs.readdirSync(dir); console.log(files); files.forEach((item, index) => { var fullPath = path.join(dir, item); const stat = fs.statSync(fullPath); if (stat.isDirectory()) { readFileList(path.join(dir, item), filesList); } else { filesList.push(fullPath); } }); return filesList; } var filesList = []; readFileList(__dirname,filesList);
|