乐趣区

关于node.js:nodejs递归文件夹获取所有文件路径

读取文件夹

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
}
退出移动版