node3_path.join和path.basename、path.extname用法

const path = require('path')
// ../会抵消一级路径
const pathStr =  path.join('/a','/b/c','../','./d','e')
console.log(pathStr)
//凡是涉及到路径拼接的问题,都要使用path.join方法,不能直接使用+

  

 

 path.basename用法:

const Path =require('path')
const fullPath = 'a/b/index.html'
let name = Path.basename(fullPath)//index.html,第一个参数是获取带有后缀的文件名
console.log(name)
name = Path.basename(fullPath,'.html')//第二个参数是去掉文件名的后缀
console.log(name)

  

 

const path = require('path')
const fullPath= 'a/b/index.html'
const ext = path.extname(fullPath)
console.log(ext)
//获取文件后缀

  

 

posted @ 2022-11-01 11:57  SadicZhou  阅读(37)  评论(0编辑  收藏  举报