1.path.basename(path[, ext])
● path <string>
● ext <string> An optional file extension
● Returns: <string>
只会返回路径的最后一部分 第二个参数用于截取
path.basename('/foo/bar/baz/asdf/quux.html');
// Returns: 'quux.html'
path.basename('/foo/bar/baz/asdf/quux.html', '.html');
// Returns: 'quux' 2.path.dirname(path)
● path <string>
● Returns: <string>
用于返回文件目录路径
path.dirname('/foo/bar/baz/asdf/quux');
// Returns: '/foo/bar/baz/asdf' 3.path.extname(path)
● path <string>
● Returns: <string>
用于返回路径文件的后缀名
path.extname('index.html');
// Returns: '.html'
path.extname('index.coffee.md');
// Returns: '.md'
path.extname('index.');
// Returns: '.'
path.extname('index');
// Returns: ''
path.extname('.index');
// Returns: '' 4.path.isAbsolute(path)
● path <string>
● Returns: <boolean>
判断是否是绝对路径
path.isAbsolute('//server'); // true
path.isAbsolute('\\\\server'); // true
path.isAbsolute('C:/foo/..'); // true
path.isAbsolute('C:\\foo\\..'); // true
path.isAbsolute('bar\\baz'); // false
path.isAbsolute('bar/baz'); // false
path.isAbsolute('.'); // false 5.path.join([...paths])
● ...paths <string> A sequence of path segments
● Returns: <string>
将字符串路径连接起来
path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
// Returns: '/foo/bar/baz/asdf'
path.join('foo', {}, 'bar');
// throws 'TypeError: Path must be a string. Received {}' 6.path.normalize(path)
● path <string>
● Returns: <string>
path.normalize('/foo/bar//baz/asdf/quux/..'); 7.path.parse(path)
● path <string>
● Returns: <Object> path.parse('/home/user/dir/file.txt');
// Returns:
// { root: '/',
// dir: '/home/user/dir',
// base: 'file.txt',
// ext: '.txt',
// name: 'file' } 8.path.relative(from, to)
● from <string>
● to <string>
● Returns: <string>
从一个路径到另一个路径的相对路径
path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb');
// Returns: '../../impl/bbb' 9.path.resolve([...paths])
● ...paths <string> A sequence of paths or path segments
● Returns: <string>
从右向左执行,直到绝对路径为止;如果路径执行完成还未找到绝对路径;则自动添加当前目录路径,注意:会执行 ..
path.resolve('/foo/bar', './baz');
// Returns: '/foo/bar/baz'
path.resolve('/foo/bar', '/tmp/file/');
// Returns: '/tmp/file'
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif');
// if the current working directory is /home/myself/node,
// this returns '/home/myself/node/wwwroot/static_files/gif/image.gif'

node path的更多相关文章

  1. node path.resolve()

    作用: path.resolve()方法将一系列路径或路径段解析为绝对路径. 语法: path.resolve([from ...], to) 说明:将参数 to 位置的字符解析到一个绝对路径里. 参 ...

  2. node path的几个路径问题

    __dirname: 总是返回被执行的 js 所在文件夹的绝对路径 __filename: 总是返回被执行的 js 的绝对路径 process.cwd(): 总是返回运行 node 命令时所在的文件夹 ...

  3. node path的一些理解笔录

    例子假如我们有这样的文件结构: app/ -lib/ -common.js -model -task.js -test.js 执行代码: var path = require("path&q ...

  4. node - path路径

    1.node命令路径与js文件路径 node命令路径为node命令所执行的目录,js文件路径指的是你要运行的js所在的目录. 如上图所示: server.js路径为E:\zyp: node命令路径我们 ...

  5. node path模块

    一.在nodejs中path模块时使用频率很高的模块,其中不乏有很多API写得很模糊,但仔细琢磨下来,也不是很难理解. 1.获取文件所在路径 var path = require('path'); v ...

  6. node的核心模块path

    //导入模块path var path=require("path"); //path.basename :输出文件名+后缀 //console.log(path.basename ...

  7. node & grunt path处理相关

    在nodejs平台上写一些工具或者服务, 有很多需求会涉及到对目录或者文件路径的处理和操作.整理一些常用的处理path的方法 1.global __dirname Example: running n ...

  8. 极简 Node.js 入门 - 2.1 Path

    极简 Node.js 入门系列教程:https://www.yuque.com/sunluyong/node 本文更佳阅读体验:https://www.yuque.com/sunluyong/node ...

  9. node安装笔记

    安装node.js1.下载node可以直接下载二进制,也可以下载源代码再安装.我选择下载二进制: https://nodejs.org/dist/v4.6.0/node-v4.6.0-linux-x6 ...

随机推荐

  1. 删除window10没用的服务

    最近学习了下resin,出了个问题,它默认端口是8080,跟Tomcat冲突了,我在使用的时候遇到了个奇怪的事情,resin4.0一直占用着我的8080端口,哪怕我用dos命令把它强制停止,不出五秒钟 ...

  2. JDK版本更换,Eclipse中所有的项目报错

    我将JDK10切换成JDK8版本以后,原先在eclipse中写的项目全部都报错了.解决方案如下: 1.设置eclipse中的JDK版本和JRE环境:window-preference-java-Com ...

  3. 「AHOI / HNOI2017」单旋

    「AHOI / HNOI2017」单旋 题目链接 H 国是一个热爱写代码的国家,那里的人们很小去学校学习写各种各样的数据结构.伸展树(splay)是一种数据结构,因为代码好写,功能多,效率高,掌握这种 ...

  4. Openstack window 10 镜像制作

    Windows 10 Openstack 镜像制作 //************************************************************************ ...

  5. [Python] 练习代码

    # from random import randrange # num = int(input('摇几次骰子: ')) # sides=int(input('筛子有几个面: ')) # sum=0 ...

  6. 003_生成器(generator)内部解析

    #http://kb.cnblogs.com/page/87128/(未看完)

  7. [教程]教你如何制作彩色的3D打印Groot

    http://mc.dfrobot.com.cn/forum.php?mod=viewthread&tid=24916 准备工作: <ignore_js_op>  3D打印高精度G ...

  8. Json的生成和解析

    json是常见的数据格式,生成和解析是常用的操作.Android中,默认提供orgJson供我们使用,除此之外,google也提供了Gson库方便我们开发. Json样例类 package com.f ...

  9. Winform开发框架之字段权限控制

    在我的很多Winform开发项目中(包括混合框架的项目),统一采用了权限管理模块来进行各种权限的控制,包括常规的功能权限(按钮.菜单权限).数据权限(记录的权限),另外还可以进行字段级别的字段权限控制 ...

  10. 深入理解Java中的反射机制

    JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意方法和属性:这种动态获取信息以及动态调用对象方法的功能称为java语言的反射机制. ...