问题描述
我有用于读取目录递归和给定深度的代码,但我写了这段代码
通过使用 var fs= require("fs");
所以我的代码看起来像这样
async function checkFileLoc(folderPath,depth) {
depth -= 1;
let files = await fs.readdir(folderPath);
files = await Promise.all(
files.map(async (file) => {
const filePath = path.join(folderPath,file);
const stats = await fsPromises.stat(filePath);
if (stats.isDirectory() && depth > 0) {
return checkFileLoc(filePath,depth);
} else if (stats.isFile()) return filePath;
else return null;
})
);
return files
.reduce((all,folderContents) => all.concat(folderContents),[])
.filter((e) => e != null);
}
我希望使用用户传递的具有一定深度的 fs-extra
包编写相同的代码
知道如何将此代码转换为 fs-extra
代码
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)