当前目录为D:\node ,以下为对比测试:
const path = require("path");
console.log(path.resolve("a"));
console.log(path.join("a"));
console.log(path.resolve("/a"));
console.log(path.join("/a"));
console.log(path.resolve("/a",'b'));
console.log(path.resolve("/a",'/b'));
console.log(path.join("/a",'b'));
console.log(path.join("/a",'/b'));
console.log(path.resolve('a','b','/c','d'));
console.log(path.resolve("a", "b", "/c", "/d"));
console.log(path.resolve('a','..','b'))
console.log(path.join('a','b','/c','d'));
console.log(path.join("a", "b", "/c", "/d"));
console.log(path.join('a','..','b'))
总结,path.resolve() 会把/ 当做根目录,且以最后一个/ 为根目录。
console.log(path.resolve("a", "b", "/c", "/d"));
|