Skip to content

Instantly share code, notes, and snippets.

@pyadav
Created August 9, 2015 08:31
Show Gist options
  • Save pyadav/0ad189ebf78678b4277b to your computer and use it in GitHub Desktop.
Save pyadav/0ad189ebf78678b4277b to your computer and use it in GitHub Desktop.
// promisify-node is necessary to turn node callback functions in Promises
let promisify = require("promisify-node");
let fs = promisify('fs');
let path = require('path');
let dir = '/home/jaydson.gomes/public_html';
async function statDir() {
// Asynchronous node fs.readdir return Promises
let list = await fs.readdir(dir);
let filesInfo = [];
for (let i = 0; i < list.length; i += 1) {
// Asynchronous node fs.stat
let info = await fs.stat(path.join(dir, list[i]));
filesInfo.push(Promise.resolve(info));
}
return Promise.all(filesInfo);
}
(async function() {
let info = await statDir();
console.log(info);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment