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

230
Vistas
How to create a file inside a folder?

I have

fileUploadPath="d:/downloads"; 

and

entry.name='155ce0e4-d763-4153-909a-407dc4e328d0/63690689-e183-46ae-abbe-bb4ba5507f1a_MULTI_0_3/output/res2/res2.fcs';

when try to create res2.fcs file with following above path it shows gives me error, why it is not creating the folder structure?

code:

data.entries.forEach(entry => {
    console.log(entry.name);
    if (fs.existsSync(fileUploadPath)) {
        var sourceFilePath = fileUploadPath + '/' + entry.name;
        if (!fs.existsSync(sourceFilePath)) {
            fs.mkdir(sourceFilePath, {recursive: true }, (err) => {if (err) {
                    console.log("Failed :" + err);
                } else {
                    const fstream = fs.createWriteStream(require('path').format({dir: fileUploadPath, base: entry.name })); fstream.write('fileContent');
                    fstream.end();
                    fstream.on("finish", f => {
                        console.log(f)
                    });
                    fstream.on("error", e => {
                        console.log(e)
                    });
                }
            });
        } else {
            console.log('d');
        }
    } else {
        console.log('ssss')
    }
})

  

error:

[Error: ENOENT: no such file or directory, open 'D:\downloads\626a69d18d2468c5082fc6e1\MULTI_1_2022-04-28_11-00-38\output\res1\res1.fcs'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'D:\\downloads\\626a69d18d2468c5082fc6e1\\MULTI__2022-04-28_11-00-38\\output\\res1\\res1.fcs'
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you're passing file path to .mkdir instead of folder, so you should first create a folder, and then write the file

(as you're creating a folder that has the same name as the file, you should've got EISDIR error, instead of this one, which also says the file write didn't work)

use path.dirname to extract folder and pass it to .mkdir:

// require path module at the top of the script
const path = require('path');


fs.mkdir(path.dirname(sourceFilePath), { recursive: true }, (err) => {
//...
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