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

add task solution #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add task solution #239

wants to merge 1 commit into from

Conversation

4xmplme
Copy link

@4xmplme 4xmplme commented Nov 2, 2024

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Great job on implementing the moveFiles function! 🎉 Your code meets the task requirements and handles the basic logic for moving files effectively. While there are some potential improvements, such as checking if the source file exists before moving it and considering cross-filesystem compatibility, these do not impact the core functionality. Keep up the good work and consider these enhancements for future projects to make your code even more robust! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +4 to +34
function moveFiles(source, destination) {
if (!source) {
// eslint-disable-next-line no-console
console.error('No source provided');

return;
}

if (!destination) {
// eslint-disable-next-line no-console
console.error('No destination provided');

return;
}

const isDirectory =
destination.endsWith('/') ||
(fs.existsSync(destination) && fs.lstatSync(destination).isDirectory());
let destinationPath = destination;

if (isDirectory) {
destinationPath = path.join(destination, path.basename(source));
}

fs.rename(source, destinationPath, (error) => {
if (error) {
// eslint-disable-next-line no-console
console.error(error);
}
});
}

Choose a reason for hiding this comment

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

Consider adding a check to verify if the source file exists before attempting to move it. This can prevent errors when the source file does not exist.

Comment on lines +28 to +33
fs.rename(source, destinationPath, (error) => {
if (error) {
// eslint-disable-next-line no-console
console.error(error);
}
});

Choose a reason for hiding this comment

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

The fs.rename function is used here to move files. Be aware that this function may not work across different file systems. If you need to ensure compatibility across different file systems, consider using fs.copyFile followed by fs.unlink to manually move the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants