readdirSync with some useful options: recursively, exclude name and ext, get only file or directory.
npm install readdirsync2 --save
const readdirSync = require('readdirsync2');
readdirSync('./foo/bar');
readdirSync('./foo/bar', {only: 'file'});
readdirSync('./foo/bar', {only: 'directory'});
readdirSync('./foo/bar', {recursive: false});
readdirSync('./foo/bar', {ignoreExt: ['.js', '.txt']});
readdirSync('./foo/bar', {ignoreName: ['index.js', 'my-folder']});
Read directory content
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
dir | string | directory path |
|
[opts] | Object | options |
|
[opts.ignoreExt] | Array | [] | an array of extensions to ignore, eg: '.txt' |
[opts.ignoreName] | Array | [] | an array of filename or directory to ignore, eg: 'index.js' |
[opts.only] | string | get file or directory or both. The value can be: |
|
[opts.recursive] | boolean | true | lookup also in nested directories |
You can view the changelog here
readdirsync2 is open-sourced software licensed under the MIT license