当前位置:网站首页>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)
边栏推荐
- 興奮神經遞質——穀氨酸與大腦健康
- Who are you and I
- ArcGIS construction and release of simple road network data service and rest call test
- DM8:生成DM AWR报告
- Go build server Foundation
- ceshi deces
- 1-18 创建最基本的express服务器&创建路由的API模块
- ArcGIS构建发布简单路网Network数据服务及Rest调用测试
- 做一个 Scrollbar 的思考
- Arcmap|assign values to different categories of IDS with the field calculator
猜你喜欢
防范未授权访问攻击的十项安全措施
Understand what MySQL index push down (ICP) is in one article
Reading notes of Clickhouse principle analysis and Application Practice (3)
SQL server extracts pure numbers from strings
介绍一款|用于多组学整合和网络可视化分析的在线平台
用yml文件进行conda迁移环境时的报错小结
Introduction of 3D Max fine model obj model into ArcGIS pro (II) key points supplement
全面认识痛风:症状、风险因素、发病机理及管理
根据肠道微生物组重新思考健康饮食
Radar data processing technology
随机推荐
给苏丹国安德森苏丹的撒过 d s g
Two skylines
sdfsdf
测试媒资缓存问题
加密与解密以及OpenSSL的应用
MySQL advanced 3
1-17 express中间件
Can flinksql two Kafka streams join?
激发新动能 多地发力数字经济
How to run jenkins build, in multiple servers with ssh-key
雷达数据处理技术
Three techniques for reducing debugging time of embedded software
《ClickHouse原理解析与应用实践》读书笔记(1)
.netcore redis GEO类型
go搭建服务器基础
Why have the intelligent investment advisory products collectively taken off the shelves of banks become "chicken ribs"?
Open source internship experience sharing: openeuler software package reinforcement test
Multi table operation - foreign key constraint
企业保护 API 安全迫在眉睫
利用日志服务器输出各种apache的日志的TOPN