Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
as an option for *nix
var exec = require('child_process').exec;
exec('cp -r /path/to/dir1 /path/to/dir2', function(error, stdout, stderr){...})
fs.readdir and for each file - fs.createReadStream / fs.createWriteStream / util.pump
1. run fs.readDir on the folder.
2. in the callback we go and say fs.stat to the response line
3. in the callback we look at the file or folder. If the folder - then 1. In any case, saves the list as a folder and the list of files
4.When everything is ready ...
5.create the necessary folders in the right place
6.read the files from the source and write to the destination, here you need to watch something the number of threads is not off scale for max-open-files(100-300)
7. you can also chmodize files with the data from point 2
All actions are asynchronous.
For unknown reasons, it works several orders of magnitude faster than rsync in the case of a full data transfer.
npm install ncp
var ncp = require('ncp').ncp;
ncp(source, destination, function (err) {
if (err) { return console.error(err); }
console.log('done!');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question