Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
vpashko committed Mar 1, 2024
1 parent b0b0065 commit 6f3ee35
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
/* eslint-disable no-console */
'use strict';

const fs = require('fs');
const path = require('path');

const [, , sourceFile, destinationFile] = process.argv;

function copyFile() {
if (!sourceFile || !destinationFile) {
console.error('Usage: node app.js <sourceFile> <destinationFile>');

return;
}

if (path.resolve(sourceFile) === path.resolve(destinationFile)) {
console.log('Source and destination are the same. Nothing to copy.');

return;
}

fs.readFile(sourceFile, (err, data) => {
if (err) {
console.error('Error reading source file:', err);

return;
}

fs.writeFile(destinationFile, data, (error) => {
if (error) {
console.error('Error writing to destination file:', err);

return;
}

console.log(`File copied from ${sourceFile} to ${destinationFile}`);
});
});
}

copyFile();

module.exports = {
copyFile: copyFile,
};

0 comments on commit 6f3ee35

Please sign in to comment.