Path模块部分常用函数解析——NodeJS
官网地址:https://nodejs.org/api/path.html
path.resolve([...paths])#
功能:该函数将一个路径序列或路径片段组合成一个绝对路径;
path.resolve([path1][, path2][, ...]) 从右向左依次拼接该路径序列,直到构成一个绝对路径。例如,输入参数:/foo, /bar, baz, 调用函数path.resolve('/foo', '/bar', 'baz')后返回结果是 /bar/baz;
如果处理完所有参数仍然没有构成一个绝对路径,就使用当前工作目录的绝对路径;结果返回的路径是经normalized后的,尾随斜线是没有的,除非是根路径;
Zero-length path segments are ignored.
如果路径序列中没有可用的路径片段,该函数将返回当前工作目录的绝对路径;
例子:
path.resolve('/foo/bar', './baz')
// Return: '/foo/bar/baz'
path.resolve('/foo/bar', '/tmp/file/')
// Return: '/tmp/file'
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
//如果当前工作目录是/home/myself/node,
//返回结果是: '/home/myself/node/wwwroot/static_files/gif/image.gif'
如果有任何参数不是字符串,将会抛出TypeError错误;
path.join([...paths])#
The path.join() method joins all given path segments together using the platform specific separator as a delimiter, then normalizes the resulting path.
作用:该函数使用指定分隔符将参数中所有路径片段连接到一起,并返回normalize后的结果路径。
Zero-length path segments are ignored. If the joined path string is a zero-length string then '.'will be returned, representing the current working directory.
如果连接的参数长度为0字符串,将会返回'.' , 表示当前工作目录
例子:
path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')
//Return: '/foo/bar/baz/asdf'
path.join('foo', {}, 'bar')
//throws TypeError:Arguments to path.join must be strings
如果参数中有任何路径片段不是字符串,将会抛出TypeError错误;
path.normalize(path)#
The path.normalize() method normalizes the given path, resolving '..' and '.' segments.
作用:标准化路径,处理'..'和'.'
When multiple, sequential path segment separation characters are found (e.g. / on POSIX and \on Windows), they are replaced by a single instance of the platform specific path segment separator. 后缀分隔符将保留;
If the path is a zero-length string, '.' is returned, representing the current working directory.
如果path是长度为0的字符串,将会返回'.' , 表示当前工作目录
For example on POSIX:
path.normalize('/foo/bar//baz/asdf/quux/..')
// Returns: '/foo/bar/baz/asdf'
On Windows:
path.normalize('C:\\temp\\\\foo\\bar\\..\\')
//Returns: 'C:\\temp\\foo\\'
path.format(pathObject)#
The path.format() method returns a path string from an object. This is the opposite ofpath.parse().
When providing properties to the pathObject remember that there are combinations where one property has priority over another:
pathObject.rootis ignored ifpathObject.diris providedpathObject.extandpathObject.nameare ignored ifpathObject.baseexists
For example, on POSIX:
// If `dir`, `root` and `base` are provided,
// `${dir}${path.sep}${base}`
// will be returned. `root` is ignored.
path.format({
root: '/ignored',
dir: '/home/user/dir',
base: 'file.txt'
});
// Returns: '/home/user/dir/file.txt' // `root` will be used if `dir` is not specified.
// If only `root` is provided or `dir` is equal to `root` then the
// platform separator will not be included. `ext` will be ignored.
path.format({
root: '/',
base: 'file.txt',
ext: 'ignored'
});
// Returns: '/file.txt' // `name` + `ext` will be used if `base` is not specified.
path.format({
root: '/',
name: 'file',
ext: '.txt'
});
// Returns: '/file.txt'
On Windows:
path.format({
dir : "C:\\path\\dir",
base : "file.txt"
});
// Returns: 'C:\\path\\dir\\file.txt'
Path模块部分常用函数解析——NodeJS的更多相关文章
- numpy.random模块常用函数解析
numpy.random模块中常用函数解析 numpy.random模块官方文档 1. numpy.random.rand(d0, d1, ..., dn)Create an array of the ...
- python重要的第三方库pandas模块常用函数解析之DataFrame
pandas模块常用函数解析之DataFrame 关注公众号"轻松学编程"了解更多. 以下命令都是在浏览器中输入. cmd命令窗口输入:jupyter notebook 打开浏览器 ...
- pandas模块常用函数解析之Series(详解)
pandas模块常用函数解析之Series 关注公众号"轻松学编程"了解更多. 以下命令都是在浏览器中输入. cmd命令窗口输入:jupyter notebook 打开浏览器输入网 ...
- python中的re模块,常用函数介绍
参考: http://www.cnblogs.com/tina-python/p/5508402.htm ======== 1,预定义字符集,可以写在字符集[....]中 \d 数字: \D 非数字 ...
- numpy模块常用函数解析
https://blog.csdn.net/lm_is_dc/article/details/81098805 numpy模块以下命令都是在浏览器中输入. cmd命令窗口输入:jupyter note ...
- 输入输出流类iostream常用函数解析
原创作品,转载请注明出处:http://www.cnblogs.com/shrimp-can/p/5657192.html 一.成员类型 1. ios::fmtflags: 格式标志,常用来设置输出的 ...
- tensorflow常用函数解析
一.tf.transpose函数的用法 tf.transpose(input, [dimension_1, dimenaion_2,..,dimension_n]):这个函数主要适用于交换输入张量的不 ...
- python3中,os.path模块下常用的用法总结
abspath basename dirname exists getatime getctime getmtime getsize isabs isdir isfile islink ismount ...
- # nodejs模块学习: express 解析
# nodejs模块学习: express 解析 nodejs 发展很快,从 npm 上面的包托管数量就可以看出来.不过从另一方面来看,也是反映了 nodejs 的基础不稳固,需要开发者创造大量的轮子 ...
随机推荐
- 微信小程序-tab标签栏实现教程
一.摘要 tab栏(标签切换栏)是app中常见的一种交互方式,它可以承载更多的内容,同时又兼顾友好体验的优点.但在小程序中,官方并没有为咱们提供现成的组件.因此我们程序员展现才艺的时候到了(其实市面上 ...
- 在C代码中将结构体变量作为参数传递效率忒低
在C语言编程中,我们几乎不可能看见有人将一个结构体变量作为参数进行传递,因为效率太低了.本文尝试从反汇编的角度给出其中的缘由. 对于C语言来说,所有的参数传递都是值传递.如果一个变量为指针,那么传递的 ...
- Linux中常用头文件的作用--转
http://blog.sina.com.cn/s/blog_5c93b2ab0100q62k.html 1. Linux中一些头文件的作用: <assert.h>:ANSI C.提供断言 ...
- [Git & GitHub] 利用Git Bash进行第一次提交文件
转载:https://blog.csdn.net/dietime1943/article/details/72420042 利用Git Bash进行第一次提交文件 快下班的时候,MD群里有人问怎么向g ...
- Java入门系列-17-多态
这篇文章贯穿游戏中的一些功能带你掌握多态的使用 为什么要使用多态 在一款对战类游戏中(如有雷同纯属巧合),有两个不同的法师英雄:小乔.妲己. 两个法师英雄的都有攻击的方法,小乔的攻击伤害为10,消耗魔 ...
- java并发编程(3)避免活跃性危险
活跃性危险 一.死锁 发生:每个人都不愿意放弃自己的锁,确想要别人的锁,这就会导致死锁 1.锁顺序死锁:如果每个线程以固定的顺序获取锁,那么至少在程序中不会出现锁顺序导致的死锁: 因为顺序固定如:所 ...
- [转].Net Core Web应用发布至IIS后报“An error occurred while starting the application”错误
本文转自:http://www.cnblogs.com/TomGui/p/6438686.html An error occurred while starting the application. ...
- wrqer
- 在CentOS 7下更改yum源与更新系统
在CentOS 7下更改yum源与更新系统. [1] 首先备份/etc/yum.repos.d/CentOS-Base.repo cp /etc/yum.repos.d/CentOS-Base.rep ...
- sql: Compare Tables
---使用 UNION.INTERSECT 或 EXCEPT 运算符合并的所有查询必须在其目标列表中有相同数目的表达式 select * from BookInfoList --存在不同的 selec ...