https://github.com/devtin/deep-list-dir
Deeply lists a directory filtering files by given pattern(s)
https://github.com/devtin/deep-list-dir
Last synced: about 1 year ago
JSON representation
Deeply lists a directory filtering files by given pattern(s)
- Host: GitHub
- URL: https://github.com/devtin/deep-list-dir
- Owner: devtin
- License: mit
- Created: 2020-05-27T15:41:30.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T20:44:03.000Z (about 3 years ago)
- Last Synced: 2025-02-07T07:36:54.878Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 349 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# deep-list-dir
> Deeply lists a directory filtering files by given pattern(s)
[](https://github.com/devtin/deep-list-dir/actions)
This module recursively 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:
```
├── dir1
│ └── README.md
├── dir2
│ └── sub-dir2
│ ├── hi.txt
│ └── index.js
├── index.js
└── README.md
```
...and the following script:
```js
const { deepListDir, deepListDirSync } = require('deep-list-dir')
deepListDir('',
{
pattern: ['*.md'], // minimatch or RegExp
// base: '', set parent base to something different than given directory
// minimatchOptions: { matchBase: true } // minimatch options
}
).then(console.log)
```
Will output
```json
[
"dir1/README.md",
"README.md"
]
```
A sync version is also provided:
```js
console.log(deepListDirSync('', { pattern: '*.js'}))
```
Output:
```json
[
"dir2/sub-dir2/index.js",
"index.js"
]
```
* * *
### License
[MIT](https://opensource.org/licenses/MIT)
© 2020-present Martin Rafael Gonzalez