微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 node js 将 fs 代码转换为 fs-extra

如何解决使用 node js 将 fs 代码转换为 fs-extra

我有用于读取目录递归和给定深度的代码,但我写了这段代码 通过使用 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 举报,一经查实,本站将立刻删除。