{"size": 824, "ext": "js", "max_stars_repo_path": "04-copy-directory/index.js", "max_stars_repo_name": "aytsaN/HTML-builder", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "04-copy-directory/index.js", "max_issues_repo_name": "aytsaN/HTML-builder", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "04-copy-directory/index.js", "max_forks_repo_name": "aytsaN/HTML-builder", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.75, "max_line_length": 67, "alphanum_fraction": 0.6759708738}
const { copyFile, mkdir, rm, readdir } = require('fs/promises')
const path = require('path')

const sourcePath = path.join(__dirname, '/files')
const destinationPath = path.join(__dirname, '/files-copy')

const createDir = async function(path) {
  await rm(path, { recursive: true, force: true })
  await mkdir(path)
}

const copyDir = async function (srcDir, destDir) {
  try {
    await createDir(destDir)

    const contentDir = await readdir(srcDir, {withFileTypes: true})

    contentDir.forEach(async el => {
      const srcElPath = path.join(srcDir, el.name)
      const destElPath = path.join(destDir, el.name)

      await el.isDirectory() ?
        copyDir(srcElPath, destElPath) :
        copyFile(srcElPath, destElPath)
    })
  } catch(err) {
    console.error(err);
  }
}

copyDir(sourcePath, destinationPath)
