Loading... **目录结构:** <div class="tip inlineBlock share simple"> - www // 文件夹 - test // 文件夹 - a.txt - index.js </div> 定义一个isDir方法判断一个资源是目录还是文件 获取wwwroot里面所有的资源 循环遍历 ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` const fs = require('fs') function isDir(path) { return new Promise((resolve, reject) => { fs.stat(path, (err, stats) => { if (err) { console.log(err) reject(err) return } if (stats.isDirectory()) { resolve(true) } else { resolve(false) } }) }) } function main() { let path = './www' let pathData = [] fs.readdir(path, async (err, data) => { if (err) { console.log(err) return } for (var i = 0; i < data.length; i++) { const el = data[i] // console.log(el, await isDir('./www/' + el)) if (await isDir('./www/' + el)) { pathData.push(el) } } console.log(pathData) }) } main() ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` Last modification:September 5, 2023 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 如果觉得我的文章对你有用,请随意赞赏