Socket
Socket
Sign inDemoInstall

recursive-readdir-filter

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    recursive-readdir-filter

Get an array of all files in a directory and subdirectories. Supports filters.


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
6.92 kB
Created
Weekly downloads
 

Readme

Source

#recursive-readdir-filter

This is a fork of https://github.com/jergason/recursive-readdir.

It adds support for filtering files and folders.


A simple Node module for recursively listing all files in a directory, or in any subdirectories.

It does not list directories themselves.

Installation

npm install recursive-readdir-filter

Usage

Just like recursive-readdir

var recursive-readdir = require('recursive-readdir-filter');

recursive-readdir('some/path', function (err, files) {
  // Files is an array of filename
  console.log(files);
});

But now with filters;

var options = {
    filterDir: function (stats) {
        return stats.name !== 'node_modules';
    },
    filterFile: function (stats) {
        return stats.name.match(/\.js$/);
    }
};

recursive-readdir('some/path', options, function (err, files) {
    console.log(files);
});

Options

Options are completly optional;

Both options must be a function. A Stats object is passed to them, but with some extra information added:

  • path: the full path to the file/folder. e.g. /Volumes/Home/foo.txt.
  • name: the name of file/folder. e.g foo.txt.
  • folder: the parent folder of the file/folder. e.g. /Volumes/Home.
{
  dev: 2114,
  ino: 48064969,
  mode: 33188,
  nlink: 1,
  uid: 85,
  gid: 100,
  rdev: 0,
  size: 527,
  blksize: 4096,
  blocks: 8,
  atime: Mon, 10 Oct 2011 23:24:11 GMT,
  mtime: Mon, 10 Oct 2011 23:24:11 GMT,
  ctime: Mon, 10 Oct 2011 23:24:11 GMT,
  name: 'a',
  path: '/Volumes/Home/Projects/recursive-readdir/test/testdir/a/a/'
  folder: '/Volumes/Home/Projects/recursive-readdir/test/testdir/a/'
}

filterDir

Is run whenever a folder is found.

filterFile

Is run whenever a file is found.

Keywords

FAQs

Last updated on 08 Mar 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc