前端之家收集整理的这篇文章主要介绍了
nodejs 读取目前下所有文件,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
var fs = require(‘fs‘);
var join = require(‘path‘).join;
function getJsonFiles(jsonPath) {
let jsonFiles = [];
function findJsonFile(path) {
let files = fs.readdirSync(path);
files.forEach(function (item,index) {
let fPath = join(path,item);
let stat = fs.statSync(fPath);
if (stat.isDirectory() === true) {
findJsonFile(fPath);
}
if (stat.isFile() === true) {
jsonFiles.push(fPath);
}
});
}
findJsonFile(jsonPath);
console.log(jsonFiles);
}
getJsonFiles("test");
?