A blazing fast recursive directory crawler with lazy sync and async iterator support.
npm install get-all-files``sh`
$ npm i get-all-files
`js
import { getAllFiles, getAllFilesSync } from 'get-all-files'
// Lazily iterate over filenames asynchronously
for await (const filename of getAllFiles(path/to/dir/or/file)) {
// Could break early on some condition and get-all-files
// won't have unnecessarily accumulated the filenames in an array
console.log(filename)
}
// Get array of filenames asynchronously
console.log(await getAllFiles(path/to/dir/or/file).toArray())
// Lazily iterate over filenames synchronously
for (const filename of getAllFilesSync(path/to/dir/or/file)) {
// Could break early on some condition and get-all-files
// won't have unnecessarily accumulated the filenames in an array
console.log(filename)
}
// Get array of filenames synchronously
console.log(getAllFilesSync(path/to/dir/or/file).toArray())`
#### getAllFiles(path[, options])
Returns a lazy
async iterable/iterator
that asynchronously iterates over the file paths recursively found at path in
no particular order.
Calling toArray on the returned value returns a promise that resolves to an
array of the file paths.
#### getAllFilesSync(path[, options])
Returns a lazy
iterable/iterator
that iterates over the file paths recursively found at path in no particular
order.
Calling toArray on the returned value returns an array of the file paths.
#### path
Type: string
A path to a file or directory to recursively find files in.
#### options
Type: object
##### Properties
###### resolve
Type: boolean\false
Default:
Whether to resolve paths to absolute paths (relative to process.cwd()).
###### isExcludedDir
Type: (dirname: string) => boolean\() => false
Default:
A predicate that determines whether the directory with the given dirnameisExcludedFile
should be crawled. There is no option because you can excludegetAllFiles.sync
files by checking conditions while lazily iterating using orgetAllFiles.async`.
Stars are always welcome!
For bugs and feature requests,
please create an issue.