path路径模块的使用
1、basename返回文件名
let path = require(‘path‘); let str = path.basename(‘/foo/bar/baz/asdf/test.html‘, ‘.html‘); console.log(str);
运行
2、join将所有的路径段连接成完整路径
let path = require(‘path‘); let str = path.basename(‘/foo/bar/baz/asdf/test.html‘, ‘.html‘); console.log(str); let pth = path.join(‘/foo‘,‘bar‘,‘baz/asdf‘,‘test‘); console.log(pth);
运行:
3、resolve将一系列的路径段解析成绝对路径
let path = require(‘path‘); let abspath = path.resolve(‘wwwroot‘, ‘static_files/png/‘, ‘../gif/image.gif‘); console.log(abspath);
运行效果如下:
原文地址:https://www.cnblogs.com/wntd/p/9689549.html
时间: 2024-12-19 00:16:08