-
Notifications
You must be signed in to change notification settings - Fork 302
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
base: master
Are you sure you want to change the base?
add task solution #239
Conversation
There was a problem hiding this 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! ✨
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); | ||
} | ||
}); | ||
} |
There was a problem hiding this comment.
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.
fs.rename(source, destinationPath, (error) => { | ||
if (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
} | ||
}); |
There was a problem hiding this comment.
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.
No description provided.