Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

read-dir-files

mmalecki3.7k0.1.1

Recursively read files from a directory

fs, recursive, file

readme

read-dir-files

Module for recursively (and non-recursively) reading all files in a directory.

Installation

npm install read-dir-files

Usage

  var readDirFiles = require('read-dir-files');
  readDirFiles('directory', function (err, files) {
    if (err) return console.dir(err);
    console.dir(files);
  });

readDirFiles(dir, encoding, recursive, callback)

Parameters:

  • dir Directory to read files from
  • encoding Files encoding. Optional.
  • recursive Recurse into subdirectories? Optional, default true.
  • callback Callback. Optional.

Asynchronously reads all files from dir and returns them to the callback in form:

{
   dir: {
     file0: <Buffer ...>,
     file1: <Buffer ...>,
     sub: {
      file0: <Buffer ...>
    }
  }
}

If you pass it the encoding, instead of buffers you'll get strings.