# recur-readdir

> recursively read all files and directories within a directory

Latest version **0.0.1** (published 2017-11-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install recur-readdir
pnpm add recur-readdir
yarn add recur-readdir
bun add recur-readdir
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2017-11-09 |
| First published | 2017-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.x |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dan Neumann |
| Maintainers | danneu |

## Links

- npm: https://www.npmjs.com/package/recur-readdir
- npm.io page: https://npm.io/package/recur-readdir

## Recent versions

- 0.0.1 (latest) — 2017-11-09

## README

# recur-readdir

    npm install recur-readdir

Recursively enumerate all files and directories within a directory.

Returns a `Map` of absolute file paths to Node's `fs.Stats` object.

```javascript
const {crawl, crawlSync} = require('recur-readdir')
const {join} = require('path')

crawl(join(__dirname, 'testDir'))
    .then(console.log, console.error)
```

## Usage

- Async: `crawl` (returns a Promise)
- Sync: `crawlSync`

Pass in options as the second argument. Here are the defaults:

```javascript
crawl(path, {
    depth: Infinity,
    filter: (path, stats) => true
})
```

Depth controls how deep to crawl. A depth of `0` returns
an empty map.

```javascript
// Only get the files and directories immediately inside the target dir.
crawl(path, { depth: 1 })
```

Only files/dirs that satisfy the filter will be included in the results.
The filter does not stop recursion.

For example, this crawl will ignore the `.secret` directory
and return only files:

```javascript
// .
// ├── a.txt
// ├── b.txt
// ├── nest1
// │   └── nest2
// │       └── nested.txt
// └── .secret
//    └── password.txt
const filter = (path, stats) => {
    return !path.includes('/.secret/') && stats.isFile()
}

crawl(path, { filter }).then(map => Array.from(map.keys()))
// ['/Users/user/example/a.txt', '/Users/user/example/b.txt', '/Users/user/example/nest1/nest2/nested.txt']
```

## Why

Other published modules weren't general enough for me.

I didn't just want file nodes, and I wanted a generalized filter
predicate.

---
_Source: https://npm.io/package/recur-readdir · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
