路径1。normalize()将非标准路径字符串转换为标准路径字符串解析..和.stringsinthepathstring,andreturntheparsedstandardpathConvertmultipleslashstringstooneslashstring,例如将\\转换为\将windows操作系统中的反斜杠字符串转换为正斜杠字符串如果路径字符串以斜杠结尾string,保留转换后的全路径字符串末尾的斜杠stringconstpath=require('path');console.log(path.normalize('../../a//b/./c'));/***窗户:..\..\a\b\c*Linux:../../a/b/c***/2.join()将多个参数值字符串合并为一个路径字符串constpath=require('path');console.log(path.join('user','name'));console.log(path.join(__dirname,'user','name'));/***windows:*user\name*Node.jsNotes\01node_core\user\name*linux:*user/name*Node.jsNotes/01node_core/user/name***/3。path.resolve()根据当前文件所在目录解析出一个绝对路径constpath=require('path');console.log(path.resolve('user','name','mark'));/***Node.jsNotes/01node_core/user/name/mark***/4.path.relative(from,to)用于获取两个路径的相对关系constpath=require('path');console.log(path.relative('/usr/local','/usr/games'));/***../游戏***/5.path.basename(path,[ext])获取路径中的文件名path必须是文件的完整路径ext方法中使用去掉返回文件名中文件的扩展名constpath=require('path');console.log(path.basename('./userinfo.txt','.txt'));/***userinfo***/6.path.extname()获取路径时文件扩展名没有扩展名,返回空字符串constpath=require('path');console.log(path.extname('./filename.txt'));/***.txt***/7。path.sep操作系统指定的文件分隔符constpath=require('path');console.log(path.sep);/***windows:\\*linux:/***/8.path。delimiter操作系统指定路径delimiterconstpath=require('path');console.log(path.delimiter);/***windows:;*linux::***/
