Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

350
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda