Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
DariaNastas committed Dec 29, 2024
1 parent c9647d4 commit c23aa34
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
// write code here
const fs = require('fs');
const path = require('path');

let destination = process.argv[3];
const sourceFile = process.argv[2];

try {
const destinationIsDirectory =
fs.existsSync(destination) && fs.statSync(destination).isDirectory();

if (destinationIsDirectory) {
const newFileName = path.basename(sourceFile);

destination = path.join(destination, newFileName);
}

fs.renameSync(sourceFile, destination);
} catch (error) {
global.console.error(error);
}

0 comments on commit c23aa34

Please sign in to comment.