Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Count all files with specific type in folder

I'm kinda new to coding, and I need to count files with specific type in my folder, but I don't know how to do it using fs module!

My current code:

const fs = require('fs'); 
fs.readdir(dir, (err, files) => {
    console.log(files.length)
});

Can someone help me?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use path.extname like this:

const fs = require('fs'); 
const path = require('path');
fs.readdir(dir, (err, files) => {
    const result = files.filter(f => path.extname(f).toLowerCase() === yourExtension).length
    console.log(result)
});

Also, as mentioned by MegaMix_Craft, take care about the variable yourExtension. It has to have the dot .value. As an example it should be .js not only js.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!