recursive-readdir
Get an array of all files in a directory and subdirectories.
Last updated 11 years ago by jergason .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install recursive-readdir 
SYNC missed versions from official npm registry.

recursive-readdir

Build Status

Recursively list all files in a directory and its subdirectories. It does not list the directories themselves.

Because it uses fs.readdir, which calls readdir under the hood on OS X and Linux, the order of files inside directories is not guaranteed.

Installation

npm install recursive-readdir

Usage

var recursive = require("recursive-readdir");

recursive("some/path", function (err, files) {
  // `files` is an array of file paths
  console.log(files);
});

It can also take a list of files to ignore.

var recursive = require("recursive-readdir");

// ignore files named "foo.cs" or files that end in ".html".
recursive("some/path", ["foo.cs", "*.html"], function (err, files) {
  console.log(files);
});

You can also pass functions which are called to determine whether or not to ignore a file:

var recursive = require("recursive-readdir");

function ignoreFunc(file, stats) {
  // `file` is the path to the file, and `stats` is an `fs.Stats`
  // object returned from `fs.lstat()`.
  return stats.isDirectory() && path.basename(file) == "test";
}

// Ignore files named "foo.cs" and descendants of directories named test
recursive("some/path", ["foo.cs", ignoreFunc], function (err, files) {
  console.log(files);
});

Promises

You can omit the callback and return a promise instead.

var recursive = require("recursive-readdir");

recursive("some/path").then(
  function(files) {
    console.log("files are", files);
  },
  function(error) {
    console.error("something exploded", error);
  }
);

The ignore strings support Glob syntax via minimatch.

Current Tags

  • 2.2.3                                ...           latest (2 years ago)

16 Versions

  • 2.2.3                                ...           2 years ago
  • 2.2.2                                ...           7 years ago
  • 2.2.1                                ...           8 years ago
  • 2.1.1                                ...           8 years ago
  • 2.1.0                                ...           8 years ago
  • 2.0.0                                ...           9 years ago
  • 1.3.0                                ...           9 years ago
  • 1.2.1                                ...           10 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.3                                ...           10 years ago
  • 1.1.2                                ...           10 years ago
  • 1.1.1                                ...           11 years ago
  • 1.1.0                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
  • 0.0.2                                ...           11 years ago
  • 0.0.1                                ...           13 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 6
Last Day 0
Last Week 6
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)

Copyright 2013 - present © cnpmjs.org | Home |