Skip to content

Instantly share code, notes, and snippets.

@jmoberly
Created March 24, 2014 20:47
Show Gist options
  • Save jmoberly/9748829 to your computer and use it in GitHub Desktop.
Save jmoberly/9748829 to your computer and use it in GitHub Desktop.
Recursively look at the files under a directory
var fs = require('fs');
var traverseFileSystem = function (currentPath) {
console.log(currentPath);
var files = fs.readdirSync(currentPath);
for (var i in files) {
var currentFile = currentPath + '/' + files[i];
var stats = fs.statSync(currentFile);
if (stats.isFile()) {
console.log(currentFile);
}
else if (stats.isDirectory()) {
traverseFileSystem(currentFile);
}
}
};
traverseFileSystem('..');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment