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) //获取文件后缀
标签:console,log,join,basename,path,fullPath,const From: https://www.cnblogs.com/SadicZhou/p/16847239.html