read-dir-deep

Returns a sorted recursive list of all files inside a directory

MIT 20 个版本
安装
npm install read-dir-deep
yarn add read-dir-deep
pnpm add read-dir-deep
bun add read-dir-deep
README

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

版本列表
8.0.0 2023-11-15
7.0.1 2019-07-10
7.0.0 2019-07-10
6.0.1 2019-06-25
6.0.0 2019-05-17
5.0.0 2019-04-22
4.0.4 2019-04-22
4.0.3 2019-03-04
4.0.2 2019-01-15
4.0.1 2019-01-15
4.0.0 2019-01-15
3.0.0 2019-01-08
2.0.0 2019-01-05
1.0.6 2019-01-05
1.0.5 2019-01-04
1.0.4 2018-07-25
1.0.3 2018-07-24
1.0.2 2018-05-24
1.0.1 2018-05-24
1.0.0 2018-05-24