File Stats Size
NodeJS
Medium
4 views
Problem Description
Read a file path and print its size in bytes.
Input Format
stdin: file path.
Output Format
Print integer bytes.
Constraints
If missing print 0.
Official Solution
const fs = require('fs');
const p = fs.readFileSync(0, 'utf8').trim();
if (!p) process.exit(0);
try {
const st = fs.statSync(p);
console.log(st.size);
} catch (e) {
console.log(0);
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!