Jeremy Banks Jeremy Banks - 1 year ago 174
Node.js Question

How do I move file a to a different partition or device in Node.js?

I'm trying to move a file from one partition to another in a Node.js script. When I used

I received
Error: EXDEV, Cross-device link
. I'd copy it over and delete the original, but I don't see a command to copy files either. How can this be done?

Answer Source

You need to copy and unlink when moving files across different partitions. Try this,

var fs = require('fs');
//var util = require('util');

var is = fs.createReadStream('source_file');
var os = fs.createWriteStream('destination_file');

is.on('end',function() {

/* node.js 0.6 and earlier you can use util.pump:
util.pump(is, os, function() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download