Last active
September 25, 2018 04:14
-
-
Save oscarr-reyes/a5142f3a0c1ccff57b57b719c30b9178 to your computer and use it in GitHub Desktop.
Get stats for all directories in a path
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
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