nodejs copy and rename file
//copy the $file to $dir2
var copyFile = (file, dir2)=>{
//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(file);
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/'
copyFile('./test/dir_1/file1.htm', './test/');
Also in JavaScript:
- javascript skip default parameter
- webpack css not shoud be empty
- disable a button react
- sum elements in list with same name js
- javascript how-do-i-remove-a-property-from-a-javascript-object
- querySelectorAll by id regex
- electron send message from renderer to main
- unterminated character class react native
- what is a 0 based language
- javascript round to 2 digits
- activar funcion js con id
- the path argument must be of type string. received undefined react
- error message remove after checkbox fill in jquery
- javascript flat object
- how to create instance of class in javascript
- javascript prototype explained
- fill checkbox javascript
- salvar no localStorage react
- play sound with keydown javascript
- 3. What are private member variables. in js
- how to add array numbers in javascript
- json unmarshal golang example
- js format urcurency
- sort by string react