Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerobugs-oficial/a8261cbc730af69c9df14d197086b0e7 to your computer and use it in GitHub Desktop.
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
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