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

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

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 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