readfolder-recursive
Read Folder Recursive
Accepts the path of a folder and returns all the files included in the folder and its subfolders.
npm i readfolder-recursive
Arguments
- The path of the folder (required)
- An array with file extensions [".png", ".mp4"]. Only the files that their extensions matches would be returned. An empty array will return all the files. (optional)
- An array with file extensions to ignore. The files with these extnesions would not be returned. (optional)
****If an extension is include in both arrays, files with this extension would not be returned.
Usage - Returns a Promise
Example 1
const readFolderRecursive = require('readfolder-recursive');
const path = "C:\Users\myUsername\Desktop\myFolder";
const extensionsToInclude = []; //An empty array means include all the files.
const extensionsToIgnore = [".mp4"]; //Ignore all the .mp4 files.
const files = await readFolderRecursive(path, extensionsToInclude, extensionsToIgnore);
It will return all the files from the folder "C:\Users\myUsername\Desktop\myFolder" apart from the .mp4 files
Example 2
const readFolderRecursive = require('readfolder-recursive');
const path = require('path');
const folder = path.join('__dirname', 'myFolder');
readFolderRecursive(folder, [], [])
.then((files)=>{ console.log(files) })
.catch((e)=>{ console.log(e) });
It will return all the files from the folder "myFolder"