27 lines
523 B
JavaScript
27 lines
523 B
JavaScript
const path = require('path');
|
|
|
|
const p = '/var/sample.txt';
|
|
|
|
// containing dir
|
|
console.log(path.dirname(p));
|
|
// filename
|
|
console.log(path.basename(p));
|
|
// ext
|
|
console.log(path.extname(p));
|
|
// file name without ext
|
|
console.log(path.basename(p, path.extname(p)));
|
|
|
|
// build abs path
|
|
const userName = 'steve';
|
|
console.log(
|
|
path.resolve('/', 'users', userName, 'notes.txt')
|
|
);
|
|
// full path with cwd
|
|
console.log(
|
|
path.resolve('sample.txt')
|
|
);
|
|
// normalize
|
|
console.log(
|
|
path.resolve('/users/steve/..//sample.txt')
|
|
);
|