-
Notifications
You must be signed in to change notification settings - Fork 312
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
developed #246
base: master
Are you sure you want to change the base?
developed #246
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
/* eslint-disable no-console */ | ||
// write code here | ||
const fs = require('fs/promises'); | ||
const path = require('path'); | ||
|
||
async function moveFile() { | ||
const [source, destination] = process.argv.slice(2); | ||
|
||
if (!source || !destination) { | ||
console.log(!source); | ||
console.error('Please enter source file and destination'); | ||
|
||
return; | ||
} | ||
|
||
if (source === destination) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be helpful to provide an error message here to inform the user that the source and destination are the same, which is why the operation is not proceeding. |
||
} | ||
|
||
const fileName = path.basename(source); | ||
let newDestination = destination; | ||
|
||
try { | ||
const destStat = await fs.stat(newDestination).catch(() => null); | ||
|
||
if ((destStat && destStat.isDirectory()) || newDestination.endsWith('/')) { | ||
newDestination = path.join(newDestination, fileName); | ||
} | ||
|
||
await fs.rename(source, newDestination); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
||
moveFile(); |
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 console.log statement here seems unnecessary and might be a leftover from debugging. Consider removing it to clean up the output.