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

228
Views
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 answers
Answer question

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