nodejs recursively read directory
var fs = require('fs');
var path = require('path');
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var i = 0;
(function next() {
var file = list[i++];
if (!file) return done(null, results);
file = path.resolve(dir, file);
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
results = results.concat(res);
next();
});
} else {
results.push(file);
next();
}
});
})();
});
};
And to test it out on your home directory (WARNING: the results list will be huge if you have a lot of stuff in your home directory):
walk(process.env.HOME, function(err, results) {
if (err) throw err;
console.log(results);
});
Also in JavaScript:
- gif command discordjs
- not equal to in js
- stripe stripe js
- how to append element in array angular
- reactjs web3 components
- node js mysql starter github
- check to see if number is a decimal javascript
- vuejs :class
- button not exist js
- render a list using array filter react
- filesaver.min.js cdn
- javascript randint
- jquery on scroll down
- glide.js autoplay
- sort array of objects by string property value
- jquery wrap inner text
- nodejs recursively read directory
- how sent data to dilaog angular material
- random int from interval javascript
- Angular 9 tutorial
- angular material inline list
- integers to space separated string in javascript
- math random equitative js
- how play audio js