nodejs 获取指定路径下所有的文件夹名

时间:2022-08-01 12:31:18

示例:获取 ./components 下所有的文件夹名称

let components = []
const files = fs.readdirSync('./components')
files.forEach(function (item, index) {
    let stat = fs.lstatSync("./components/" + item)
    if (stat.isDirectory() === true) { 
      components.push(item)
    }
})

console.log(components);