# sb-scandir

> File scanning module for Node.js

Latest version **3.1.1** (published 2025-06-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install sb-scandir
pnpm add sb-scandir
yarn add sb-scandir
bun add sb-scandir
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2025-06-04 |
| First published | 2016-08-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 8 |
| Dependencies | 1 |
| Unpacked size | 17.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | steelbrain |
| Maintainers | steelbrain |
| Keywords | scandir, steelbrain, files, scan |

## Links

- npm: https://www.npmjs.com/package/sb-scandir
- Repository: https://github.com/steelbrain/scandir
- Homepage: https://github.com/steelbrain/scandir#readme
- Issues: https://github.com/steelbrain/scandir/issues
- npm.io page: https://npm.io/package/sb-scandir

## Dependencies (1)

- [sb-promise-queue](https://npm.io/package/sb-promise-queue.md) ^2.1.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 3.1.1 (latest) — 2025-06-04
- 3.1.0 — 2020-08-03
- 3.0.0 — 2020-05-03
- 2.0.0 — 2017-09-18
- 1.0.0 — 2016-08-21

## README

# ScanDir

`sb-scandir` is a node module that supports simple file scanning with some sugar features.

## Installation

```
npm install --save sb-scandir
```

## API

```js
interface Result {
  files: Array<string>
  directories: Array<string>
}

interface FileSystem {
  join(pathA: string, pathB: string): string
  basename(path: string): string
  stat(path: string): Promise<fs.Stats>
  readdir(path: string): Promise<string[]>
}

type Validate = (path: string) => boolean

export const defaultFilesystem: FileSystem;

export default async function scanDirectory(
  path: string,
  {
    recursive = true,
    validate = null,
    concurrency = Infinity,
    fileSystem = defaultFilesystem,
  }: {
    recursive?: boolean
    validate?: Validate | null
    concurrency?: number
    fileSystem?: Partial<FileSystem>
  } = {},
): Promise<Result>;
```

## Examples

```js
import Path from 'path'
import scandir, { defaultFilesystem } from 'sb-scandir'
// or
const { default: scandir, defaultFilesystem } = require('sb-scandir')

// Scan all files except the dot ones
scandir(__dirname).then(function(result) {
  console.log('files', result.files)
  console.log('directories', result.directories)
})

// Scan all top level files except dot ones
scandir(__dirname, { recursive: false }).then(function(files) {
  console.log('files', result.files)
  console.log('directories', result.directories)
})

// Scan all files even the dot ones
scandir(__dirname, { recursive: true, validate(path) {
  return true
}}).then(function(files) {
  console.log('files', result.files)
  console.log('directories', result.directories)
})

// Scan all files except in .git and node_modules
scandir(__dirname, { recursive: true, validate(path) {
  const baseName = Path.basename(path)
  return baseName !== '.git' && baseName !== 'node_modules'
}}).then(function(files) {
  console.log('files', result.files)
  console.log('directories', result.directories)
})
```

## License

This project is licensed under the terms of MIT License. See the LICENSE file for more info.

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