const fs = require("fs"); let fileArr = []; const dir = "E:/Hbuilder-Content/7.19新增页面"; main(dir); console.log(fileArr); function main(currentPath) { if (currentPath === dir && fileArr.length != 0) return fileArr; fileArr = []; getDirs(currentPath); function getDirs(path) { let files; try { files = fs.readdirSync(path, { encoding: "utf8", withFileTypes: true }); } catch (error) { return; } files.forEach((file) => { if (file.isDirectory()) { getDirs(path + "/" + file.name); } else { fileArr.push(dir + "/" + file.name); } }); } }
标签:files,遍历,nodejs,currentPath,fileArr,文件夹,file,getDirs,dir From: https://www.cnblogs.com/laremehpe/p/16882964.html