Created
July 20, 2017 02:47
-
-
Save helton/876f7e97c7ee61cb1f6ece5cd54ed1bc to your computer and use it in GitHub Desktop.
Full Stack Academy - Aula 01 - Exercicio 05
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
/* | |
* [Exercício 5 - extra] | |
* | |
* Dado a lista de arquivos/diretórios retornada no exercício anterior, | |
* mostre quais são arquivos. | |
* (utilize fs.stat(caminho, (err, stat) => stat.isFile()) para isso.) | |
*/ | |
const fs = require('fs') | |
const readdirPromise = (path) => new Promise((resolve, reject) => | |
fs.readdir(path, (err, files) => | |
err ? reject(err) : resolve(files) | |
) | |
) | |
const readFileStats = (path) => new Promise((resolve, reject) => | |
fs.stat(path, (err, stats) => | |
err ? reject(err) : resolve({ path, isFile: stats.isFile() }) | |
) | |
) | |
const showFilesOnly = async (path) => { | |
const paths = await readdirPromise(path) | |
const stats = await Promise.all(paths.map(readFileStats)) | |
const filesOnly = stats.filter(stat => stat.isFile) | |
console.log(filesOnly); | |
} | |
showFilesOnly('./') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Certinho Helton. Recomendo que de uma olhada nesse vídeo também: https://www.youtube.com/watch?v=nnsz91rhWuA