2023-02-26 01:30
This commit is contained in:
26
getting-started/16_path.js
Normal file
26
getting-started/16_path.js
Normal file
@@ -0,0 +1,26 @@
|
||||
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')
|
||||
);
|
||||
Reference in New Issue
Block a user