const fs = require("fs"); function getFileList(path) { const list = fs.readdirSync(path, { encoding: 'utf-8' }); return list.map(item => { const isFile = fs.statSync(`${path}/${item}`).isFile(); return isFile ? item : getFileList(`${path}/${item}`); }) } const file = getFileList("./in"); file = file.flat(Infinity) console.log(file); //效果如下图