- I am trying to write automation script using node js what i am trying to achieve is I have packages in one machine and install those packages in another machine..i need to write a script for it..
- packages has config and jar files... I need to open the config file and change the installer value and execute the .exe file
- For example in the config file i have value like this PPP.install= iphone
- I need to change it to
- PPP.install= android
- and after that I need to execute .exe file. both config and exe file are in the same folder.
- right now what I have achieved is i can copy all these files in to a another folder I need to unzip and zip it too.. not sure how to achieve... can i copy all these files in to a another folder
- providing my code below
var fs = require('fs');
var path = require('path');
/*function dateFormat(){
var date = new Date();
var year = (date.getFullYear() + '').slice(2);
var month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1);
var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
return year+month+day;
}*/
function moveAndRename(sourceDir, destDir){
fs.readdir(sourceDir, function(err, files){
if(err)
return err;
else {
files.forEach(function(file){
var dotIndex = file.lastIndexOf(".");
var name = file.slice(0, dotIndex);
//var newName = (name + dateFormat()) + path.extname(file);
var newName = (name) + path.extname(file);
var read = fs.createReadStream(path.join(sourceDir, file));
var write = fs.createWriteStream(path.join(destDir, newName));
read.pipe(write);
});
}
});
}
moveAndRename("C:/here/Desktop/screenshots/folder1",
"C:/here/Desktop/screenshots/folder2")