I develop the process, often encountered, to copy the template to the current folder, often to go to the file, in order to save trouble, to solve this problem, wrote a node copy file.
//Flow Stream Pipeline pipe pipe//You can use data events if you want full control when reading streams and writing to the stream. However, for simple file replication, read and write streams can be piped to transmit data. varFS = require ("FS");varPath = require ("Path");/** Copy all files in directory including subdirectories * @src param{String} directories to be copied images or./images/* @dst param{String} copied to the specified directory example images Images/*/ //gets the current directory absolute path, where resolve () does not pass in ParametersvarFilePath =path.resolve ();varcopy =function (SRC,DST) {//To determine if the file takes time, you must synchronize if(Fs.existssync (src)) {Fs.readdir (Src,function (err,files) {if(ERR) {Console.log (ERR);return;} Files.foreach (function (filename) {//url+ "/" +filename not available/direct connection, UNIX system is "/", Windows system is "\" varURL =Path.join (src,filename), dest=Path.join (dst,filename); Console.log (URL); Console.log (dest); Fs.stat (Path.join (Src,filename), function (err, stats) {if(ERR)Throwerr; //is a file if(Stats.isfile ()) {//Create read streamreadable =fs.createreadstream (URL); //Create write Streamwritable = Fs.createwritestream (dest,{encoding:"UTF8" }); //to transport a stream through a pipelinereadable.pipe (writable); //If the directory}Else if(Stats.isdirectory ()) {exists (URL, dest, copy); } }); }); }); }Else{Console.log ("The given directory does not exist, and the file is not read"); return; }}function exists (url,dest,callback) {fs.exists (dest,function (exists) {if(exists) {callback&&callback (Url,dest); }Else{ //second parameter directory permissions, default 0777 (read and Write permissions)Fs.mkdir (dest,0777, function (err) {if(ERR)Throwerr; Callback&&callback (Url,dest); }); } });} Exports.copy=copy;//copy ("./views/", "./www/");Copy"./.. /jdcase/homeappliances/", FilePath);
Node Copy file