Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
Nodejs how to read directory and grab certain files

in my Nodejs project, i have a folder named input that contains green-1.png, green-2.png, green-3.png,red-1.png, red-2.png, red-3.png files

i want to read the input directory and grab only the all the green files.

i tried this code :

 const { promisify } = require('util')

 const readdir = promisify(fs.readdir)

 const files = await readdir('../input')

it works fine but it gets me all green and red files from input folder.

how can i get only all the green ones?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

fs.readdir will get all the contents of a folder. There is no way to filter the files in the function.

The best you can do is filter the files to those that are green

const filteredFiles = files.filter((f) => f.includes('green'));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda