//引入核心对象path
const path = require('path');
//智能拼接路径(自动省略\和/)
let myPath = path.join(__dirname,'one','//two//','//three///');
console.log(myPath); // E:\webcode\one\two\three
//相对路径转绝对路径(自动省略\和/)
const str = './//abc1.js';
let temp = path.resolve(str);
console.log(temp); // E:\webcode\abc\1.js
//路径转换为对象,获取路径各种信息
let myPath = "E:\\webcode\\abc\\1.js";
let pathObj = path.parse(myPath);
console.log(pathObj);
/*
{
root:"E:\\",
dir:"E:\\webcode\\abc",
base:"1.js",
ext:".js",
name:"1",
}
*/
// 路径对象转换成路径字符串
let myPath = path.format(pathObj);
console.log(myPath); // E:\webcode\abc\1.js