path模块

 一、dirname

作用:动态获取当前文件夹的绝对路径

二、filename

作用:动态获取当前文件的绝对路径

三、path.jion([path1][, path2][, ...])

作用:使用当前系统路径分隔符连接路径

四、path.resolve([from ...], to)

作用:相当于将from cd 到 to,/被解析为根路径。

console.log(__dirname);   //   F:\myProject\vue.config.js    
console.log(__dirname);  //    F:\myProject\

 

let myPath = path.join(__dirname,'/img/so');
let myPath2 = path.join(__dirname,'./img/so');
let myPath3=path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
 
      
console.log(myPath);    // F:\myProject\img\so
console.log(myPath2);   // F:\myProject\img\so
console.log(myPath3);   // F:\myProject\foo\bar\bar\asdf  **** ..表示返回上一层

 

 

let myPath = path.resolve(__dirname,'/img/so');
let myPath2 = path.resolve(__dirname,'./img/so');
let myPath3=path.resolve('/foo/bar', './baz');
let myPath4=path.resolve('/foo/bar', '/tmp/file/'); 

console.log(myPath);       //   \img\so
console.log(myPath2);   //     F:\myProject\img\so
console.log(myPath3);    //  \foo\bar\bar
console.log(myPath4);    //   \tmp\file

 

posted @ 2020-03-14 15:23  2350305682  阅读(161)  评论(0编辑  收藏  举报