https://github.com/okdistribute/folder-walker
Get a stream of files walking recursively through a folder
https://github.com/okdistribute/folder-walker
Last synced: 5 months ago
JSON representation
Get a stream of files walking recursively through a folder
- Host: GitHub
- URL: https://github.com/okdistribute/folder-walker
- Owner: okdistribute
- Created: 2015-11-18T08:00:28.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-09-11T01:18:50.000Z (over 6 years ago)
- Last Synced: 2024-12-30T00:04:38.851Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 21.5 KB
- Stars: 48
- Watchers: 6
- Forks: 9
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# folder-walker
A recursive stream of the files and directories in a given folder. Can take multiple folders.
[](http://travis-ci.org/karissa/folder-walker)
## Install
```console
npm install folder-walker
```## Example
```js
var walker = require('folder-walker')
var stream = walker(['/path/to/folder', '/another/folder/here'])
stream.on('data', function (data) {
console.log(data)
})
```Example item in the stream:
```js
{
basename: 'index.js',
relname: 'test/index.js',
root: '/Users/karissa/dev/node_modules/folder-walker',
filepath: '/Users/karissa/dev/node_modules/folder-walker/test/index.js',
stat: [fs.Stat Object],
type: 'file' // or 'directory'
}
```## API
#### `stream = walker(dirs, [opts])`
Create a readable object stream of all files and folders inside of `dirs`.
`dirs` can be a path to a directory or an array of paths to directories.
`opts` includes:
```js
{
fs: require('fs'), // the fs interface to use
maxDepth: Infinity // maximum folder depth to walk. Minimum depth is 1.
filter: function (filename) { return true } // a function that lets you filter out files by returning false
// filter is applied to the `dirs` argument, and every file that folder-walker finds
}
```