Skip to content

Commit

Permalink
analog of linux`s cp command was done
Browse files Browse the repository at this point in the history
  • Loading branch information
2pasha committed Feb 15, 2024
1 parent b0b0065 commit b9475f0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
/* eslint-disable no-console */
'use strict';

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

const copy = (sorce, destination) => {
const sourcePath = path.resolve(sorce);
const destinationPath = path.resolve(destination);

if (!fs.existsSync(sourcePath)) {
console.error('Source file does not exist');
}

fs.copyFileSync(sourcePath, destinationPath);
console.log(`File ${sorce} copied to ${destination}`);
};

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

if (!sourceFile || !destinationFile) {
console.error('Usage: node app.js <source_file> <destination_file>');
} else {
try {
copy(sourceFile, destinationFile);
} catch (err) {
console.error(err.message);
}
}

0 comments on commit b9475f0

Please sign in to comment.