convert fs code to fs-extra using node js

86 Views Asked by At

i have code which used to read directory recursive and with given depth but i have wrote this code by using var fs= require("fs");

so my code look like this

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);
}

I want same code to be written by using fs-extra package with certain depth which is passed by user any idea how this code can be converted into fs-extra code

0

There are 0 best solutions below