1

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?

1 Answer 1

1

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')); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.