Skip to content

Instantly share code, notes, and snippets.

@oscarr-reyes
Last active September 25, 2018 04:14
Show Gist options
  • Save oscarr-reyes/a5142f3a0c1ccff57b57b719c30b9178 to your computer and use it in GitHub Desktop.
Save oscarr-reyes/a5142f3a0c1ccff57b57b719c30b9178 to your computer and use it in GitHub Desktop.
Get stats for all directories in a path
const fs = require("fs");
const path = require("path");
const pathDir = "C:/Users/Oscar/Downloads";
const dirs = fs.readdirSync(pathDir);
dirs.forEach(async dir => {
const stats = await readStats(path.resolve(pathDir, dir));
console.log(dir, `file: ${stats.isFile()}`);
});
function readStats(dir) {
return new Promise((resolve, reject) => {
fs.lstat(dir, (err, stats) => {
if (err) {
reject(err);
}
else {
resolve(stats);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment