当前位置:网站首页>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)
边栏推荐
猜你喜欢

Arcmap|assign values to different categories of IDS with the field calculator

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

ArcGIS构建发布简单路网Network数据服务及Rest调用测试

网络营销之四大误解

《ClickHouse原理解析与应用实践》读书笔记(2)

Double solid histogram / double y-axis

双立体柱状图/双y轴

多态在代码中的体现

DM8:生成DM AWR报告

Prediction and regression of stacking integrated model
随机推荐
go搭建服务器基础
Prediction and regression of stacking integrated model
【无标题】
攻防演练中的防泄露全家福
Can flinksql two Kafka streams join?
激发新动能 多地发力数字经济
sdfsdf
The 16th Heilongjiang Provincial Collegiate Programming Contest
Why have the intelligent investment advisory products collectively taken off the shelves of banks become "chicken ribs"?
ssh 默认端口不是22时的一些问题
sdfsdf
变异系数法matlab代码[通俗易懂]
asp.net core JWT传递
jupyterbook 清空控制台输出
How to run jenkins build, in multiple servers with ssh-key
興奮神經遞質——穀氨酸與大腦健康
Test medal 1234
Arcmap|assign values to different categories of IDS with the field calculator
Reading notes of Clickhouse principle analysis and Application Practice (1)
twelve thousand three hundred and forty-five