Skip to content

Instantly share code, notes, and snippets.

@elyssonmr
Created July 20, 2017 00:18
Show Gist options
  • Save elyssonmr/d6b14a572443fb6d8643ef75e706a95c to your computer and use it in GitHub Desktop.
Save elyssonmr/d6b14a572443fb6d8643ef75e706a95c to your computer and use it in GitHub Desktop.
Exercício 5
const fs = require("fs")
function readdirPromise(path) {
return new Promise((resolve, reject) => {
fs.readdir(path, (err, files) => {
if(err){
reject(err)
}else{
resolve(files)
}
})
})
}
function checkIsFile(file) {
return new Promise((resolve, reject) => {
fs.stat(file, (err, stats) => {
if (!err) {
fileStat = {
nome: file,
ehArquivo: stats.isFile()
}
resolve(fileStat)
} else {
reject(err)
}
})
})
}
async function listDir(path) {
files = await readdirPromise(path)
let promises = []
for (var file in files) {
promises.push(await checkIsFile(files[file]))
}
Promise.all(promises).then(teste => console.log(teste))
}
const path = "./"
listDir(path)
@tuliofaria
Copy link

Certinho Elysson.
Recomendo que de uma olhada nesse vídeo: https://www.youtube.com/watch?v=nnsz91rhWuA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment