Skip to content

olegskl/walk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

walk

Build Status Code Climate

Asynchronous directory walker with recursion control.

Installation

npm install git://github.com/olegskl/walk.git

or in package.json as a dependency:

"dependencies": {
    "walk": "git://github.com/olegskl/walk.git"
}

Usage example

var walk = require('walk');

// The worker is a function applied to every item the walker steps on;
// it receives two arguments:
// 1. path - a full path of an item the walker steps on
// 2. stats - an fs.Stats object of the item,
//    see http://nodejs.org/api/fs.html#fs_class_fs_stats
function worker(path, stats) {
    if (stats.isDirectory() && path.substr(-4) === '1337') {
        console.info('Descend into "%s" because it ends with "1337"', path);
        return true;
    }
    if (stats.isFile() && /\.txt$/.test(path)) {
        console.info('Stepped on "%s" because it ends with ".txt"', path);
        // Do something with the file here,
        // maybe pass to a processing queue?..
    }
}

// The callback is called when all items have been walked:
function callback(err) {
    if (err) {
        console.error(err);
    }
    console.timeEnd('Walk finished; time spent');
}

console.time('Walk finished; time spent');
walk('path/to/dir', worker, callback);

Tests

If Mocha is not installed:

npm install

Use any of the following to run the test suite:

mocha
npm test
make test

License

http://opensource.org/licenses/mit-license.html

About

Asynchronous directory walker with recursion control.

Resources

Stars

Watchers

Forks

Packages

No packages published