Copy File

Copy File

Hard NodeJS File System & Paths 24 views
Explanation Complexity

Problem Statement

Copy a source file to destination and print COPIED.

Input Format

stdin: two paths (src dest).

Output Format

Print COPIED or FAIL.

Example

a.txt b.txt
COPIED

Constraints

Use readFileSync/writeFileSync.

Input / Output Format

Input Format
stdin: two paths (src dest).
Output Format
Print COPIED or FAIL.
Constraints
Use readFileSync/writeFileSync.

Examples

Input:
a.txt b.txt
Output:
COPIED

Example Solution (Public)

NodeJS
const fs = require('fs');
const s = fs.readFileSync(0, 'utf8').trim().split(/\\s+/);
if (s.length < 2) process.exit(0);
const src = s[0];
const dest = s[1];
try {
  const buf = fs.readFileSync(src);
  fs.writeFileSync(dest, buf);
  console.log('COPIED');
} catch (e) {
  console.log('FAIL');
}

Official Solution Code

const fs = require('fs');
const s = fs.readFileSync(0, 'utf8').trim().split(/\\s+/);
if (s.length < 2) process.exit(0);
const src = s[0];
const dest = s[1];
try {
  const buf = fs.readFileSync(src);
  fs.writeFileSync(dest, buf);
  console.log('COPIED');
} catch (e) {
  console.log('FAIL');
}
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.