Skip to content

Instantly share code, notes, and snippets.

@Sannis
Forked from vilmibm/fs.walk.js
Created September 16, 2010 23:31
Show Gist options
  • Save Sannis/583375 to your computer and use it in GitHub Desktop.
Save Sannis/583375 to your computer and use it in GitHub Desktop.
Recursive directories walk
var fs = require('fs'),
sys = require('sys');
function walk(path, callback) {
var recur_or_cb = function( abspath ) {
return function(err, stats) {
if ( stats.isDirectory() )
walk(abspath, callback);
else
callback(err, abspath);
};
};
fs.readdir(path, function(err, files) {
files.forEach(function(f) {
abspath = path + '/' + f;
fs.stat(abspath, recur_or_cb(abspath));
});
});
}
walk('/home/nate/Music', function(err, path) { sys.print(path+"\n") });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment