Created
July 20, 2017 00:22
-
-
Save caioregatieri/3cb3c7fd14fa5ee54196bb0064ab0c91 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
function readDirPromise(path) { | |
const fs = require('fs') | |
return new Promise((resolve, reject) => { | |
fs.readdir(path, (err, files) => { | |
if (err) { | |
reject(err) | |
} else { | |
resolve(files) | |
} | |
}) | |
}) | |
} | |
async function showFilesAndDirs(path) { | |
const fs = require('fs') | |
try { | |
const content = await readDirPromise(path) | |
content.forEach(function(element) { | |
var isFile = (err, stat) => { | |
console.log(element + ' é ' + (stat.isFile() ? 'um arquivo' : 'um diretorio')); | |
} | |
fs.stat(element, isFile) | |
}); | |
} catch (e) { | |
console.log(e) | |
} | |
} | |
showFilesAndDirs('./'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Para esse exercício seria interessante seguir essa abordagem: https://www.youtube.com/watch?v=nnsz91rhWuA