Created
June 23, 2020 00:50
-
-
Save zerobugs-oficial/a8261cbc730af69c9df14d197086b0e7 to your computer and use it in GitHub Desktop.
Esse script lista todos os arquivos presentes em um diretório, incluindo os que estão dentro de subdiretórios
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'); | |
function listarArquivosEPastasDeUmDiretorio(diretorio, arquivos) { | |
if(!arquivos) | |
arquivos = []; | |
let listaDeArquivos = fs.readdirSync(diretorio); | |
for(let k in listaDeArquivos) { | |
let stat = fs.statSync(diretorio + '/' + listaDeArquivos[k]); | |
if(stat.isDirectory()) | |
listarArquivosEPastasDeUmDiretorio(diretorio + '/' + listaDeArquivos[k], arquivos); | |
else | |
arquivos.push(diretorio + '/' + listaDeArquivos[k]); | |
} | |
return arquivos; | |
} | |
let lista = listarArquivosEPastasDeUmDiretorio('./arquivos'); | |
console.log(lista); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment