Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #367

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
'use strict';

const fs = require('fs');

function copyFile() {
const [file, newFile] = process.argv.slice(2);

if (!newFile) {
// eslint-disable-next-line no-console
console.error('Error: Please provide two arguments.');

return;
}

if (file === newFile) {
// eslint-disable-next-line no-console
console.error('Error: Source and destination paths cannot be the same.');

return;
}

fs.cp(file, newFile, (err) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fs.cp method is used here, which is only available in Node.js version 16.7.0 and later. If you are using an older version of Node.js, consider using fs.copyFile instead. Ensure compatibility with your Node.js version.

if (err) {
// eslint-disable-next-line no-console
console.error(`Error: ${err.message}`);
} else {
// eslint-disable-next-line no-console
console.log(`Success: File copied from "${file}" to "${newFile}".`);
}
});
}

copyFile();
Loading