获取目录树
$ npm i file-tree-simple --save
const fileTree = require('file-tree-simple')
fileTree(__dirname) // {tree<Object>, files<Array>}
/*
输出内容格式:
{ tree:
{ pathName: 'E:\\GitHub\\file-tree-simple\\test',
isFile: false,
children: [ ... ] },
files: ['E:\\GitHub\\file-tree-simple\\test\\index.js', ... ] }
*/
// 过滤文件或目录
fileTree(__dirname, {
fileFilter: ({ name }) => {
return path.extname(name + '') === '.js'
},
dirFilter: ({ name }) => {
return name !== '.cbd'
}
})