text: Q:
  
  Whats the best way to copy files from 2 diferents folders to a new one using javascript?
  
  Im setting up a program that will check two different folder and copy all the files from the in a third one. The problem for me here is how to copy them without their names?
  var fs = require("fs");
  
  fs.renameSync("/home/oem/git/test/folder1/test1.js", "/home/oem/git/test/folder1/test1CHANGED.js")
  
  console.log("file renamed");
  
  fs.rename("/home/oem/git/test/folder1/test2", "/home/oem/git/test/folder2", function(err){
      if(err)
      {
          console.log(err);
      }
      else
      {
          console.log("file moved successfully");
      }
  });
  
  with the code above i can move files that i manually write thei r names, i want to implement it somehow that it will automatically scan the folder and change them to the other one!
  
  A:
  
  Here a Function that could help you to do this
  const fs = require('fs');
  const path = require('path');
  
  function copyFiles() {
      const firstFolder = 'firstFolder';
      const secondFolder = 'secondFolder';
      const destinationFolder = 'destinationFolder';
      const firstDir = path.join(__dirname, firstFolder);
      const secondDir = path.join(__dirname, secondFolder);
      const destDir = path.join(__dirname, destinationFolder);
      fs.readdir(firstDir, (err, files) => {
          if (err) {
              throw err;
          }
          for (let i = 0; i < files.length; i += 1) {
              fs.copyFile(firstDir + '/' + files[i], destDir + '/' + files[i], function (err) {
                  if (err)
                      throw err;
              });
          }
  
      });
      fs.readdir(secondDir, (err, files) => {
          if (err) {
              throw err;
          }
          for (let i = 0; i < files.length; i += 1) {
              fs.copyFile(secondDir + '/' + files[i], destDir + '/' + files[i], function (err) {
                  if (err)
                      throw err;
              });
          }
  
      });
  }
  
  copyFiles();
  
  