| 1 | walker [](http://travis-ci.org/daaku/nodejs-walker)
|
|---|
| 2 | ======
|
|---|
| 3 |
|
|---|
| 4 | A nodejs directory walker. Broadcasts events for various file types as well as
|
|---|
| 5 | a generic "entry" event for all types and provides the ability to prune
|
|---|
| 6 | directory trees. This shows the entire API; everything is optional:
|
|---|
| 7 |
|
|---|
| 8 | ```javascript
|
|---|
| 9 | Walker('/etc/')
|
|---|
| 10 | .filterDir(function(dir, stat) {
|
|---|
| 11 | if (dir === '/etc/pam.d') {
|
|---|
| 12 | console.warn('Skipping /etc/pam.d and children')
|
|---|
| 13 | return false
|
|---|
| 14 | }
|
|---|
| 15 | return true
|
|---|
| 16 | })
|
|---|
| 17 | .on('entry', function(entry, stat) {
|
|---|
| 18 | console.log('Got entry: ' + entry)
|
|---|
| 19 | })
|
|---|
| 20 | .on('dir', function(dir, stat) {
|
|---|
| 21 | console.log('Got directory: ' + dir)
|
|---|
| 22 | })
|
|---|
| 23 | .on('file', function(file, stat) {
|
|---|
| 24 | console.log('Got file: ' + file)
|
|---|
| 25 | })
|
|---|
| 26 | .on('symlink', function(symlink, stat) {
|
|---|
| 27 | console.log('Got symlink: ' + symlink)
|
|---|
| 28 | })
|
|---|
| 29 | .on('blockDevice', function(blockDevice, stat) {
|
|---|
| 30 | console.log('Got blockDevice: ' + blockDevice)
|
|---|
| 31 | })
|
|---|
| 32 | .on('fifo', function(fifo, stat) {
|
|---|
| 33 | console.log('Got fifo: ' + fifo)
|
|---|
| 34 | })
|
|---|
| 35 | .on('socket', function(socket, stat) {
|
|---|
| 36 | console.log('Got socket: ' + socket)
|
|---|
| 37 | })
|
|---|
| 38 | .on('characterDevice', function(characterDevice, stat) {
|
|---|
| 39 | console.log('Got characterDevice: ' + characterDevice)
|
|---|
| 40 | })
|
|---|
| 41 | .on('error', function(er, entry, stat) {
|
|---|
| 42 | console.log('Got error ' + er + ' on entry ' + entry)
|
|---|
| 43 | })
|
|---|
| 44 | .on('end', function() {
|
|---|
| 45 | console.log('All files traversed.')
|
|---|
| 46 | })
|
|---|
| 47 | ```
|
|---|
| 48 |
|
|---|
| 49 | You specify a root directory to walk and optionally specify a function to prune
|
|---|
| 50 | sub-directory trees via the `filterDir` function. The Walker exposes a number
|
|---|
| 51 | of events, broadcasting various file type events a generic error event and
|
|---|
| 52 | finally the event to signal the end of the process.
|
|---|