node.js(无聊测试一)

const path = require('path')
const pathfile = '/user/a/b/c'
const pathfile2 = '/user/a/b/c/a.txt'
const pathfile3 = 'j.txt'
1.path.basename
console.log(path.basename(pathfile))  //c
console.log(path.basename(pathfile2,'.txt'))  //a.txt
2.path.dirname
// 返回path目录名
console.log(path.dirname(pathfile2)) /// user/a/b/c
3.path.extname
// 获取path路径中path的最后一部分冲最后一次出现
console.log(path.extname('extname'+ pathfile2))  //.txt
4.path.join
// 连接路径 join(不灵活)
console.log(path.join(pathfile,pathfile2))  //\user\a\b\c\user\a\b\c\a.txt
5.path.resolve
//连接路径(灵活)会将路径或路径片段的序列解析为绝对路径。
 console.log(path.resolve(pathfile2)) //E:\user\a\b\c\a.txt
 console.log(path.resolve(pathfile,pathfile3)) //E:\user\a\b\c\j.txt
6.path.parse
// 将路径以对象的形式返回
console.log(path.parse(pathfile2)); 
// {
//   root: '/',
//   dir: '/user/a/b/c',
//   base: 'a.txt',
//   ext: '.txt',
//   name: 'a'
// }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值