Created
May 10, 2021 21:02
-
-
Save Nipodemos/559f6bbea2d69322e0d2a1205c95566f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const fs = require("fs").promises; | |
| async function readFolder(path) { | |
| const dir = await fs.readdir(path); | |
| const json = {}; | |
| for (arquivo of dir) { | |
| const currentItemPath = path + "/" + arquivo; | |
| const detalhesDoArquivo = await fs.stat(currentItemPath); | |
| if (detalhesDoArquivo.isDirectory()) { | |
| // é uma pasta | |
| json[arquivo] = [await readFolder(currentItemPath)]; | |
| console.log("é uma pasta: " + arquivo); | |
| } else if (detalhesDoArquivo.isFile()) { | |
| // é um arquivo | |
| if (!json[arquivo]) { | |
| json[arquivo] = {}; | |
| } | |
| console.log("arquivo :>> ", arquivo); | |
| json[arquivo] = { | |
| name: arquivo, | |
| }; | |
| console.log("é um arquivo: " + arquivo); | |
| } | |
| } | |
| return json; | |
| } | |
| readFolder("./ARQUIVOS").then((result) => { | |
| console.log("result :>> ", result); | |
| console.log("CURITIBA FILES "); | |
| result.CURITIBA[0].forEach((item) => { | |
| console.log("item :>> ", item); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment