-
-
Save seanbehan/24bb12a1397487ecd26f214d0a64a136 to your computer and use it in GitHub Desktop.
Walk through a directory recursively in node.js.
This file contains hidden or 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"), | |
path = require("path"); | |
function walk(dir, callback) { | |
fs.readdir(dir, function(err, files) { | |
if (err) throw err; | |
files.forEach(function(file) { | |
var filepath = path.join(dir, file); | |
fs.stat(filepath, function(err,stats) { | |
if (stats.isDirectory()) { | |
walk(filepath, callback); | |
} else if (stats.isFile()) { | |
callback(filepath, stats); | |
} | |
}); | |
}); | |
}); | |
} | |
if (exports) { | |
exports.walk = walk; | |
} else { | |
walk(".", manageFile); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment