Get All Files
A blazing fast recursive directory crawler with sync and async iterator support.
Install
Supports Node.js versions 10 and above.
$ npm i get-all-files
Usage
import getAllFiles from 'get-all-files'
console.log(getAllFiles.sync.array(`path/to/dir/or/file`))
for (const filename of getAllFiles.sync(`path/to/dir/or/file`)) {
console.log(filename)
}
;(async () => {
console.log(await getAllFiles.async.array(`path/to/dir/or/file`))
for await (const filename of getAllFiles.async(`path/to/dir/or/file`)) {
console.log(filename)
}
})()
API
Methods
getAllFiles.sync(path[, options])
Returns a lazy iterable/iterator that iterates over the file paths recursively found at path
in no particular order.
getAllFiles.sync.array(path[, options])
Returns a string[]
of file paths recursively found at path
in no particular ordering.
getAllFiles.async(path[, options])
Returns a lazy async iterable/iterator that asynchronously iterates over the file paths recursively found at path
in no particular order.
getAllFiles.async.array(path[, options])
Returns a Promise<string[]>
of file paths recursively found at path
in no particular ordering.
Parameters
path
Type: string
A path of file or directory to recursively find files in.
options
Type: object
Properties
resolve
Type: boolean
Default: false
Whether to resolve paths to absolute paths (relative to process.cwd()
).
isExcludedDir
Type: (dirname: string) => boolean
Default: () => false
A predicate that determines whether the directory with the given dirname
should be crawled. There is no isExcludedFile
option because you can exclude files by checking conditions while lazily iterating usinggetAllFiles.sync
or getAllFiles.async
.
License
MIT © Tomer Aberbach