var fs = require("fs");var log = function(msg) { console.log(msg);}function copyFile(source, destination) { if (fs.existsSync(source)) { var rOption = { flags: 'r', encoding: null, mode: 0666 } var wOption = { flags: 'a', encoding: null, mode: 0666 } var stream = fs.createReadStream(source, rOption); var writable = fs.createWriteStream(destination); stream.pipe(writable, wOption); writable.on('close', function() { log('done'); }); // fs.rename(source, destination,function(){ // console.log("ok"); // }); }}//copyFile("F:\\video\\阿甘正传(1).rmvb", "D:\\阿甘正传(1).rmvb");function copyDir(dir1, dir2) { if (!fs.existsSync(dir2)) { fs.mkdirSync(dir2); } var files = fs.readdirSync(dir1); for (var i in files) { var file = files[i]; file1 = dir1 + "\\" + file; file2 = dir2 + "\\" + file; var sta = fs.statSync(file1); if (sta.isDirectory()) { copyDir(file1, file2); } else { copyFile(file1, file2); } }}copyDir("D:\\VM\\centos", "f:\\ttt")