Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

185
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda