My code is:
var files = fs.readdirSync('./archivos/'); //itera todos los archivos
for (var a in files) {
if (fs.statSync('./archivos/'+files[a]).isFile()){
var nombreFile=files[a];
console.log(files[a]);
fs.readFile('./archivos/'+nombreFile, 'utf8', function(err, data) {
console.log(nombreFile); //solo muentra el ultimo File, como solucionar?, porque solo muestra el ultimo file???
var contentA=data;
escritorLector.escribirTraining(nombreFile,contentA);
for (var b in files) {
if(fs.statSync('./archivos/'+files[b]).isFile()){
if(nombreFile!=files[b]){
fs.readFile('./archivos/'+files[b], 'utf8', function(err, data) {
var contentB=data;
fs.readFile('./archivos/training/'+nombreFile, 'utf8', function(err, data) {
var contentAnterior=data;
var contentAB=contentAnterior+contentB;
console.log(contentAB);
escritorLector.escribirTraining(nombreFile,contentAB);
});
});
}
}
};
});
}
};
that code works in 2 folders which are:
./archivos/
./archivos/training/
The logic of the code above is:
- get the contents of all the files
- create a new file in ./files/training/ for each file and put all the contents of all the files
- do that for all files, that is, create for each file de ./archivos/ your union file in ./archivos/training /
in the code, comment on the following
console.log (filename); // just move the last file, how to solve ?, because it only shows the last file ???