-
-
Save Sannis/583375 to your computer and use it in GitHub Desktop.
Recursive directories walk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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