I'm trying to move a file from my /tmp
folder to my home with node and fs
module. I try the rename method but mi tmp
partition is separated from home
so I read in https://github.com/nodejs/node-v0.x-archive/issues/2703 thats my problem was with partitions so I move to from renamme to pipe method, but when I try to move files, with some folders in it I get the following error:
Uncaught Exception:
Error: EISDIR: illegal operation on a directory, open '/tmp/torrentPlayer/2f9505e50a48838c7f769c707ed9e29cee2f03ba'
at Error (native)
I make the subdirectories tree before of this, but doesn't work and I don't know what Im doing wrong.
EDIT
My code is:
var originalPath = "/tmp/originalFolder";
var savePath = "~/someFolder"
const fs = require('fs');
const mv = require('mv');
fs.readdir(originalPath, (err, files) => {
files.forEach(function (file){
var source = fs.createReadStream(originalPath+ '/'+file);
var newFile = fs.createWriteStream(savePath+'/'+file);
// console.log(+'\n'+newFile);
source.pipe(newFile);
source.on('end', function() { console.log(newFile); });
source.on('error', function() { console.log("err"); });
})
})
But file may be a directory contains other directories.