From 7feac8d2a584076f622c27443fbe83f40d89169b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=93=B6=E5=86=9B?= Date: Sun, 23 Aug 2026 23:21:07 +0800 Subject: [PATCH] no message --- test1/path-dirname.js | 3 ++- test1/path-join.js | 8 ++++++++ test1/path.parse.js | 12 ++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test1/path-join.js create mode 100644 test1/path.parse.js diff --git a/test1/path-dirname.js b/test1/path-dirname.js index 847a58d..6e4442d 100644 --- a/test1/path-dirname.js +++ b/test1/path-dirname.js @@ -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)) \ No newline at end of file +console.log(path.dirname(testPath)) +console.log("----") diff --git a/test1/path-join.js b/test1/path-join.js new file mode 100644 index 0000000..69da863 --- /dev/null +++ b/test1/path-join.js @@ -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')) \ No newline at end of file diff --git a/test1/path.parse.js b/test1/path.parse.js new file mode 100644 index 0000000..8a927ec --- /dev/null +++ b/test1/path.parse.js @@ -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)) \ No newline at end of file