Created
August 9, 2015 08:31
-
-
Save pyadav/0ad189ebf78678b4277b to your computer and use it in GitHub Desktop.
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
// 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