Rename File

Rename File

Medium NodeJS File System & Paths 30 views
Explanation Complexity

Problem Statement

Rename a file and print RENAMED or FAIL.

Input Format

stdin: old new.

Output Format

Print one word.

Example

a.txt b.txt
RENAMED

Constraints

Use fs.renameSync.

Input / Output Format

Input Format
stdin: old new.
Output Format
Print one word.
Constraints
Use fs.renameSync.

Examples

Input:
a.txt b.txt
Output:
RENAMED

Example Solution (Public)

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

Official Solution Code

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

                                        
Please login to submit solutions.