no message

This commit is contained in:
陈银军
2026-08-23 23:21:07 +08:00
parent d53049c271
commit 7feac8d2a5
3 changed files with 22 additions and 1 deletions
+2 -1
View File
@@ -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("----")
+8
View File
@@ -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'))
+12
View File
@@ -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))