官网地址:https://nodejs.org/api/path.html

path.resolve([...paths])#

Added in: v0.3.4
  • 参数[...paths]: <String> 参数是一个路径序列或路径片段
  • 返回: <String>

功能:该函数将一个路径序列或路径片段组合成一个绝对路径;

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])#

Added in: v0.1.16

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)#

Added in: v0.1.23

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)#

Added in: v0.11.15

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.root is ignored if pathObject.dir is provided
  • pathObject.ext and pathObject.name are ignored if pathObject.base exists

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的更多相关文章

  1. numpy.random模块常用函数解析

    numpy.random模块中常用函数解析 numpy.random模块官方文档 1. numpy.random.rand(d0, d1, ..., dn)Create an array of the ...

  2. python重要的第三方库pandas模块常用函数解析之DataFrame

    pandas模块常用函数解析之DataFrame 关注公众号"轻松学编程"了解更多. 以下命令都是在浏览器中输入. cmd命令窗口输入:jupyter notebook 打开浏览器 ...

  3. pandas模块常用函数解析之Series(详解)

    pandas模块常用函数解析之Series 关注公众号"轻松学编程"了解更多. 以下命令都是在浏览器中输入. cmd命令窗口输入:jupyter notebook 打开浏览器输入网 ...

  4. python中的re模块,常用函数介绍

    参考: http://www.cnblogs.com/tina-python/p/5508402.htm ======== 1,预定义字符集,可以写在字符集[....]中 \d  数字: \D 非数字 ...

  5. numpy模块常用函数解析

    https://blog.csdn.net/lm_is_dc/article/details/81098805 numpy模块以下命令都是在浏览器中输入. cmd命令窗口输入:jupyter note ...

  6. 输入输出流类iostream常用函数解析

    原创作品,转载请注明出处:http://www.cnblogs.com/shrimp-can/p/5657192.html 一.成员类型 1. ios::fmtflags: 格式标志,常用来设置输出的 ...

  7. tensorflow常用函数解析

    一.tf.transpose函数的用法 tf.transpose(input, [dimension_1, dimenaion_2,..,dimension_n]):这个函数主要适用于交换输入张量的不 ...

  8. python3中,os.path模块下常用的用法总结

    abspath basename dirname exists getatime getctime getmtime getsize isabs isdir isfile islink ismount ...

  9. # nodejs模块学习: express 解析

    # nodejs模块学习: express 解析 nodejs 发展很快,从 npm 上面的包托管数量就可以看出来.不过从另一方面来看,也是反映了 nodejs 的基础不稳固,需要开发者创造大量的轮子 ...

随机推荐

  1. 忘记root密码的解决方法——进入单用户模式修改

    (1)在系统还在读秒的时候按任意键,你会看到如下界面: 然后按下‘e’

  2. 架构实战项目心得(七):使用SpringBoot+Dubbo+Mybatisplus+Oracle搭建后台项目框架(二)

    接下来我们将整合mybatisplus+Oracle,实现一个简单的查询.(期间踩了很多坑,遇到一些问题,还好慢慢解决了.现在是通过配置文件的方式来进行dubbo服务的注册和发布,希望以后能在学习和实 ...

  3. [转]AngularJS 实现 Table的一些操作(示例大于实际)

    本文转自:http://www.cnblogs.com/lin-js/p/linJS.html <!DOCTYPE html> <html> <head> < ...

  4. [转]微信小程序联盟 跳坑《一百八十一》设置API:wx.openSetting使用说明

    本文转自:http://www.wxapp-union.com/forum.php?mod=viewthread&tid=4066 这个API解决了过去一个长久以来无法解决的问题,如何让用户重 ...

  5. 微信小程序开发框架整理

    目前除了原生的微信小程序开发外,各大厂商陆续造了自己的开发框架,现整理如下: WePY 腾讯官方开源的小程序组件化开发框架,目前有15K+Star ,一直在更新着,社区活跃,掉坑能快速的找到方法爬出来 ...

  6. 决策树之ID3算法

    一.决策树之ID3算法简述 1976年-1986年,J.R.Quinlan给出ID3算法原型并进行了总结,确定了决策树学习的理论.这可以看做是决策树算法的起点.1993,Quinlan将ID3算法改进 ...

  7. flask之wtforms 表单验证(一)

    一  安装wtforms pip install wtforms 二  导入相关模块及对象 from wtforms import Form, widgets, validators from wtf ...

  8. jQuery多次选中checkbox失效

    在做项目的过程中,遇到一个问题.就是使用jquery的attr方法即 $("#aaa").attr('checked',true); $("#aaa").att ...

  9. mysql(什么是关系型数据库?)

    关系型数据库:建立在关系模型上的数据库. 关系模型:当将日常生活中的实体(学生),和实体的属性(学生的学号,姓名)保存到数据库中,应该如何处理实体结构. 1.数据结构可以规定,同类数据,结构一致.就是 ...

  10. python中循环删除list和dict类型注意事项

    列表和字典在循环操作(增删)时,其长度会改变 # 删除 li = [11, 22, 33, 44, 'rock']中索引为单数的元素 # 方法一 del li[1::2] print(li) # [1 ...