Skip to content

Instantly share code, notes, and snippets.

@prakashsvmx
Created February 23, 2021 06:45
Show Gist options
  • Save prakashsvmx/76a4819bdea8ef54652b6e49f9c04cdf to your computer and use it in GitHub Desktop.
Save prakashsvmx/76a4819bdea8ef54652b6e49f9c04cdf to your computer and use it in GitHub Desktop.
//copy the $file to $dir2
var copyFile = (file, dir2, fileName)=>{
//include the fs, path modules
var fs = require('fs');
var path = require('path');
//gets file name and adds it to dir2
var f = path.basename(fileName);
var source = fs.createReadStream(file);
var dest = fs.createWriteStream(path.resolve(dir2, f));
source.pipe(dest);
source.on('end', function() { console.log('Succesfully copied'); });
source.on('error', function(err) { console.log(err); });
};
//example, copy file1.htm from 'test/dir_1/' to 'test/'
const nObjects = Array.from(Array(1002).keys())
nObjects.forEach((item, index)=>{
if(index>1){
copyFile('/home/prakash/Downloads/HouseDesign/TEST/1.png', '/home/prakash/Downloads/HouseDesign/TEST/', item+'.png');
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment