Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
BodyaKutsyk committed Sep 19, 2024
1 parent ff435f3 commit 0ba8c21
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
/* eslint-disable no-console */
'use strict';

const fs = require('fs');

const [inputPath, outputPath] = process.argv.slice(2);

async function copyFile(from, to) {
let isItFile = true;

fs.stat(from, (err, stats) => {
if (err) {
console.error('File not found!');

return false;
}

isItFile = stats.isFile();
});

if (from && to && isItFile && from !== to) {
try {
const fileData = fs.readFileSync(from, 'utf-8');

fs.writeFileSync(to, fileData);
} catch (err) {
console.error(err);
}

console.log('\x1b[32m', 'File was copied succesfully!');

return;
}

console.error('File not found!');
}

copyFile(inputPath, outputPath);

module.exports = { copyFile };

0 comments on commit 0ba8c21

Please sign in to comment.