no message
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const path=require('path');
|
||||
var testPath='f:code/node/chenxuan.js'
|
||||
// path.dirname 返回路径的目录部分(去掉最后的文件名),结果为 f:code/node
|
||||
console.log(path.dirname(testPath))
|
||||
console.log(path.dirname(testPath))
|
||||
console.log("----")
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
const path=require('path');
|
||||
var testPath='f:code/node/chenxuan.js'
|
||||
|
||||
// __dirname 表示当前js文件所处的目录
|
||||
// join 拼接路径
|
||||
// '…/'会抵消掉一层路径
|
||||
console.log(path.join(__dirname,'/hehe1','/hehehe2','/hehehe3'))
|
||||
console.log(path.join(__dirname,'/hehe1','../','/hehehe3'))
|
||||
@@ -0,0 +1,12 @@
|
||||
const path=require('path');
|
||||
var testPath='f:code/node/chenxuan.js'
|
||||
|
||||
const mypath1=path.join(__dirname,'/hehe1','/hehe2','/hehe3.html');
|
||||
console.log(mypath1)
|
||||
// path.parse 将路径解析为对象,包含5个字段:
|
||||
// root - 根目录,macOS/Linux 为 '/',Windows 为盘符如 'C:\'
|
||||
// dir - 文件所在完整目录路径(不含文件名),等价于 path.dirname()
|
||||
// base - 完整文件名(名称+扩展名),等价于 path.basename()
|
||||
// ext - 文件扩展名(从最后一个点开始),如 '.html',等价于 path.extname()
|
||||
// name - 纯文件名(不含扩展名),等价于去掉 ext 后的 basename
|
||||
console.log(path.parse(mypath1))
|
||||
Reference in New Issue
Block a user