读取文件夹

fs.readdirSync('./')

判断文件类型

fs.statSync(item).isDirectory()

路径拼接

path.resolve(dir, item)

封装

function deepGetFile(dir) {
    let backList = []
    let list = fs.readdirSync(dir)

    for (let index in list) {
        let item = path.resolve(dir, list[index])
        if (fs.statSync(item).isDirectory()) {
            backList = backList.concat(deepGetFile(item))
        } else {
            backList.push(item)
        }
    }
    return backList
}

jsoncode
4k 声望786 粉丝

I'm jsoncode