varFS = require ("FS");varLog =function(msg) {Console.log (msg);}functioncopyFile (source, destination) {if(Fs.existssync (source)) {varRoption ={flags:' R ', Encoding:NULL, Mode:0666 } varWoption ={flags:A, Encoding:NULL, Mode:0666 } varstream =Fs.createreadstream (source, roption); varwritable =Fs.createwritestream (destination); Stream.pipe (writable, woption); Writable.on (' Close ',function() {log (' Done '); }); //fs.rename (source, destination,function () { //console.log ("OK"); // }); }}//CopyFile ("F:\\video\\ Forrest Gump (1). rmvb", "D:\\ Forrest Gump (1). rmvb");functioncopydir (Dir1, Dir2) {if(!Fs.existssync (DIR2)) {Fs.mkdirsync (DIR2); } varFiles =Fs.readdirsync (DIR1); for(varIinchfiles) { varFile =Files[i]; File1= Dir1 + "\ \" +file; File2= Dir2 + "\ \" +file; varSTA =Fs.statsync (FILE1); if(Sta.isdirectory ()) {copydir (file1, file2); } Else{copyFile (file1, file2); }}}copydir ("D:\\vm\\centos", "F:\\TTT")
Nodejs Copy Files