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

345
Views
Read folder created on local machine by using Math.random() method in Node js / JavaScript

I am trying to read a JSON File which is in folder within a folder and in another folder and this file is created on my local machine while performing some task but the problem is every time folder name get change as folder name is generated by Math.random() method but with prefix of _createdFolder_ so its look like this _createdFolder_012 in place of 012 it can be 454 or 782 or any number as it is generate by Math.random() method if the folder name is fixed I can easily read the file but file name get changed and its been hard to read

and I want to read a json file which is path look like this

folderPath

_createdFolder_563/data/systemCode/access.json

as I want to read and fetch json file which is created on my local machine while performing some task but if the folder name is fixed I can easily read it but due to Math.random() its hard to read a file

fs.readFile("_createdFolder_501/data/systemCode/access.json", function(err, data) {
    if (err) throw err;
   
    const JsonData = JSON.parse(data);
      
    console.log(JsonData);  
});

is there any possible way I can read the folder which is created by Math.random()

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

0

Yes.

Meet FS.readdir(path). It lists the contents of a directory.

You will need to invoke that, giving it the path to the folder that contains the randomly-named folder. That will give you a list of all the files and folders.

Then you need to search that list for an item whose name matches that pattern. Then you have the name you need, and you can do the rest of your logic.

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!