path常用方法汇总极演示:
let path = require('path');
console.log(path.basename('/app/asd/arr/cv.html'));
console.log(path.basename('/app/asd/arr/cv.html','html'));
console.log(path.dirname(__dirname));
console.log(path.dirname(__filename));
console.log(path.extname('index.html'));
let obj = path.parse(__filename);
console.log(obj);
let objpath = {
root: 'd:\\',
dir: 'd:\\aaa\\bb\\a.txt',
base: 'a.txt',
ext:'.txt',
name:'abc'
};
let strpath = path.format(objpath);
console.log(strpath);
console.log(path.join('/foo','bar','bar/asdf','nest'));
console.log(path.delimiter);
console.log(path.sep);