我有用于读取目录递归并具有给定深度的代码,但我已经通过使用编写了此代码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
代码