Miss any of our Open RFC calls?Watch the recordings here! »

deep-list-dir

1.4.0 • Public • Published

deep-list-dir

Deeply lists a directory filtering files by given pattern(s)

Version tests

This module deeply lists all files in given directory (including sub-folders) by early filtering the results using the given pattern which can be an array of minimatch expressions or RegExp.

It will return all matching results. minimatch negative patterns are used to explicitly exclude a path from being scan / returned.

Example

Take the following file structure:

<directory>
├── dir1
│   └── README.md
├── dir2
│   └── sub-dir2
│       ├── hi.txt
│       └── index.js
├── index.js
└── README.md

...and the following script:

const { deepListDir, deepListDirSync } = require('deep-list-dir')
 
deepListDir('<directory>',
  {
    pattern: ['*.md'], // minimatch or RegExp
    // base: '', set parent base to something different than given directory
    // minimatchOptions: { matchBase: true } // minimatch options
  }
).then(console.log) // => ['<directory>/dir1/README.md', '<directory>/README.md']
 
console.log(deepListDirSync('<directory>', { pattern: '*.js'}))  // => ['<directory>/dir2/sub-dir2/index.js', '<directory>/index.js']

License

MIT

© 2020-present Martin Rafael Gonzalez tin@devtin.io

Install

npm i deep-list-dir

DownloadsWeekly Downloads

57

Version

1.4.0

License

MIT

Unpacked Size

18.5 kB

Total Files

16

Last publish

Collaborators

  • avatar