admin管理员组

文章数量:1418050

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.

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.

Share Improve this question edited Sep 3, 2015 at 15:37 Qix - MONICA WAS MISTREATED 15.2k17 gold badges92 silver badges156 bronze badges asked Jul 25, 2014 at 8:26 Umesh SehtaUmesh Sehta 10.7k5 gold badges42 silver badges68 bronze badges 2
  • 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 Commented Jan 13, 2016 at 21:45
  • @Bram thanks for information :) – Umesh Sehta Commented Jan 14, 2016 at 4:50
Add a ment  | 

1 Answer 1

Reset to default 4

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

Second: ncp is what you need i guess

本文标签: javascriptnodejs Error EISDIRopen ErrorStack Overflow