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

224
Views
Picking a Random file from a folder in node

I have a fodler on my local machine and I would like to pick a random file from it. I have tried using this :

    var files = fs.readdirSync(`/Users/...`)
    random_file = files[Math.floor(Math.random() * files.length)] 

But sometimes I get this as random-file : .DS_Store

Could anyone help me fix this please

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

0

Just run a filter and return filenames !== Ds Store

files=files.filter(fileName=>fileName!==".DS_Store")
random_file = files[Math.floor(Math.random() * files.length)] 

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!