当前位置:网站首页>1-7 Path路径模块
1-7 Path路径模块
2022-06-30 21:26:00 【画不完的饼】
1-7 Path路径模块
path模块是Node.js官方提供的、用来处理路径的模块。它提供了一系列的方法和属性,用来满足用户对路径的处理需求。
路径拼接方法:
使用path.join()方法,可以把多个路径片段拼接为完整的路径字符串,语法格式如下:
path.join([…paths])
const path = require('path')
//注意:../会抵消前面的一层路径
//今后凡是涉及到路径拼接的时候,一定要使用path.join()进行拼接,不要用+号
const pathStr = path.join('/a', 'b/c', '../', './d', 'e')
console.log(pathStr)
获取路径中的文件名:
path.basename()
使用path,basename()方法,可以从一个文件路径中,获取到文件的名称部分:
const path = require('path')
const fpath = '/a/b/c/index.html'
// const fullName = path.basename(fpath)
// console.log(fullName)
const name = path.basename(fpath, '.html') //可以通过接收第二个参数(传入后缀名的方式)来获取不带后缀名的文件名称。
console.log(name)
获取路径中的扩展名:
使用path.extname()方法,可以获取路径中的扩展名的部分:
const path = require('path')
const fpath = '/a/b/c/index.html'
const fulname = path.extname(fpath)
console.log(fulname)
边栏推荐
- [grade evaluator] how to register a grade evaluator? How many passes?
- Auto-created primary key used when not defining a primary key
- 3Ds Max 精模obj模型导入ArcGIS Pro (二)要点补充
- 【等级测评师】等级测评师怎么报名?多少分及格?
- USBCAN分析仪的配套CAN和CANFD综合测试软件LKMaster软件解决工程师CAN总线测试难题
- 数字货币:影响深远的创新
- 申请Vector 总线协议彩图壁纸挂画,非常棒哦!
- ca i啊几次哦啊句iu家哦
- Coefficient of variation method matlab code [easy to understand]
- Use the log server to output the topn of various Apache logs
猜你喜欢

Introduction of 3D Max fine model obj model into ArcGIS pro (II) key points supplement
Testing media cache

jupyter notebook/lab 切换conda环境

ICML2022 | 序列决策的效用理论

DM8:生成DM AWR报告

What about degradation of text generation model? Simctg tells you the answer

jupyterbook 清空控制台输出

USBCAN分析仪的配套CAN和CANFD综合测试软件LKMaster软件解决工程师CAN总线测试难题

个人开发的渗透测试工具Satania

Open source internship experience sharing: openeuler software package reinforcement test
随机推荐
Metauniverse may become a new direction of Internet development
Three techniques for reducing debugging time of embedded software
Oprator-1 first acquaintance with oprator
Apply for vector bus protocol color picture wallpaper hanging picture, very good!
科研中遇到迷茫困惑如何向前一步?如何在科研中发挥女性优势?
布隆过滤器
WebRTC系列-网络传输之本地scoket端口
测试勋章1234
Internet of things botnet gafgyt family and backdoor vulnerability exploitation of Internet of things devices
电子方案开发——智能跳绳方案
Spatiotemporal data mining: an overview
clickhouse原生監控項,系統錶描述
. NETCORE redis geo type
Auto-created primary key used when not defining a primary key
Is it safe to open an account for stock trading on mobile phones?
全面认识痛风:症状、风险因素、发病机理及管理
FreeRTOS record (IX. an example of a bare metal project transferring to FreeRTOS)
USBCAN分析仪的配套CAN和CANFD综合测试软件LKMaster软件解决工程师CAN总线测试难题
ICML2022 | 序列决策的效用理论
利用日志服务器输出各种apache的日志的TOPN