1

I am trying to copy one folder to another using node.js here is folder path:-

D:\node\files\11\j1_1\j1_2\j1_3 I want to copy folder j1_3 to path D:\node\files\11\j1_1\

here is my code:-

var source = fs.createReadStream(old);
var dest = fs.createWriteStream(newp);
source.pipe(dest);
source.on('end', function () { /* copied */ });
source.on('error', function (err) {
    console.log("hi");
    /* error */
});

but I am getting this error:-

events.js:72
    throw er; // Unhandled 'error' event
          ^
 Error: EISDIR, open 'D:\node\files\11\j1_1'

I have also try fs.rename function but getting same error.

Qix - MONICA WAS MISTREATED
  • 14,451
  • 16
  • 82
  • 145
Umesh Sehta
  • 10,555
  • 5
  • 39
  • 68
  • one additional clarification. The error you are getting at the writestream is because fs does not automatically append the new filename to the dest. Which cp and ncp do, so to fix the issue you could have also added the new filename to the dest instead of using ncp / cp. Resulting in: newp + path.basename(old); – Bram Jan 13 '16 at 21:45
  • @Bram thanks for information :) – Umesh Sehta Jan 14 '16 at 04:50

1 Answers1

4

First: EISDIR means "error! target is a dir"(i guess), about the error

Second: ncp is what you need i guess

Community
  • 1
  • 1
rhapsodyn
  • 3,272
  • 5
  • 29
  • 36