read-dir-deep
TypeScript icon, indicating that this package has built-in type declarations

8.0.0 • Public • Published

read-dir-deep

npm

About

Returns a sorted recursive list of all files inside a directory.

Installation

npm install --save read-dir-deep

Usage

const path = require('path');
const { readDirDeep, readDirDeepSync } = require('read-dir-deep');

const rootDir = path.resolve(process.cwd(), 'nested');

// async
const files = await readDirDeep(rootDir);

// sync
const files = readDirDeepSync(rootDir);

console.log(files);
// [
//     'nested/a/b/c.js',
//     'nested/a.js',
//     'nested/b/a.js',
//     'nested/b.js',
// ]

Options

const files = await readDirDeep(rootDir, {
	/**
	 * Return files relative to this directory
	 *
	 * defaults:
	 *    inside process.cwd(): process.cwd()
	 *    outside process.cwd(): rootDir
	 */
	cwd: process.cwd(),

	/**
	 * Return full file paths
	 *
	 * defaults:
	 *     inside process.cwd: false
	 *     outside process.cwd: true
	 */
	absolute: true,

	/**
	 * Custom file matching
	 *
	 * See [globby#patterns](https://github.com/sindresorhus/globby#patterns)
	 *
	 * default: ['.']
	 */
	patterns: [
		'.',
		'!**/*.test.js',
	],

	/**
	 * Exclude files/folders
	 *
	 * default: see below
	 * See named export: defaultIgnorePatterns
	 */
	ignore: [
		'**/.DS_Store',
		'**/node_modules/**',
		'**/.git/**',
		'**/.vscode/**',
		'**/.idea/**',
		'**/dist/**',
		'**/build/**',
		'**/coverage/**',
	],

	/**
	 * Exclude files set in .gitignore
	 *
	 * default: true
	 */
	gitignore: true,
});

See Globby Options for additional options

Package Sidebar

Install

npm i read-dir-deep

Weekly Downloads

252

Version

8.0.0

License

MIT

Unpacked Size

23.9 kB

Total Files

18

Last publish

Collaborators

  • chrisblossom