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

made solution for moving files #157

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 26 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
// write code here
/* eslint-disable no-console */
'use strict';

const { moveFiles } = require('./helper');
const [source, destination] = process.argv.slice(2);

if (!source) {
console.log('Please provide source and destination files');

return;
}

if (!destination) {
console.log('Please provide destination');

return;
}

if (destination[destination.length - 1] === '/') {
const pathArray = source.split('/');
const fileName = pathArray[pathArray.length - 1];

moveFiles(source, destination + fileName);
} else {
moveFiles(source, destination);
}
21 changes: 21 additions & 0 deletions src/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const fs = require('fs');

const moveFiles = (source, destination) => {
fs.copyFile(source, destination, err => {
if (err) {
throw err;
}
});

fs.unlink(source, err => {
if (err) {
throw err;
}
});
};

module.exports = {
moveFiles,
};
1 change: 1 addition & 0 deletions src/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
General Kenobi
Loading