当前位置:网站首页>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)
边栏推荐
- 漫谈Clickhouse Join
- ceshi deces
- 多态在代码中的体现
- MySQL advanced 3
- Auto-created primary key used when not defining a primary key
- Clickhouse native monitoring item, system table description
- Spatiotemporal data mining: an overview
- Clickhouse Native Monitoring item, System table Description
- k个一组反转链表
- Multi table operation - foreign key constraint
猜你喜欢

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

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

Icml2022 | utility theory of sequential decision making

Prediction and regression of stacking integrated model

本地浏览器打开远程服务器上的Jupyter Notebook/Lab以及常见问题&设置

Five years after graduation, I wondered if I would still be so anxious if I hadn't taken the test

Multi table operation - foreign key constraint

Adobe-Photoshop(PS)-脚本开发-去除文件臃肿脚本
笔记【JUC包以及Future介绍】

AKK菌——下一代有益菌
随机推荐
遇到“word在试图打开文件时遇到错误”怎么办?
go搭建服务器基础
Auto-created primary key used when not defining a primary key
两个skyline
Encryption and decryption and the application of OpenSSL
Is it safe to open an account for stock trading on mobile phones?
等级测评是什么意思?工作流程包含哪些?
《ClickHouse原理解析与应用实践》读书笔记(2)
[grade evaluator] how to register a grade evaluator? How many passes?
Five years after graduation, I wondered if I would still be so anxious if I hadn't taken the test
Adobe-Photoshop(PS)-脚本开发-去除文件臃肿脚本
WebRTC系列-网络传输之本地scoket端口
asp.net core JWT传递
FreeRTOS record (IX. an example of a bare metal project transferring to FreeRTOS)
pytorch geometric torch-scatter和torch-sparse安装报错问题解决
jupyterbook 清空控制台输出
CA I ah, several times Oh, ah, a sentence IU home Oh
代码改变一小步,思维跨越一大步
12345
Clickhouse Native Monitoring item, System table Description