path.relative(from, to)
历史
版本 | 变化 |
---|---|
v6.8.0 | 在 Windows 上,UNC 路径的前导斜杠现在包含在返回值中。 |
v0.5.0 | 添加于:v0.5.0 |
参数
path.relative()
方法根据当前工作目录返回from
到to
的相对路径。如果 from
和 to
都解析到相同的路径(在每个都调用 path.resolve()
之后),则返回零长度字符串。
如果零长度字符串作为 from
或 to
传递,则将使用当前工作目录而不是零长度字符串。
例如,在 POSIX 上:
path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb');
// Returns: '../../impl/bbb'
在 Windows 上:
path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb');
// Returns: '..\\..\\impl\\bbb'
如果 from
或 to
不是字符串,则会抛出
。TypeError
相关用法
- Node.js path.relative()用法及代码示例
- Node.js path.resolve()用法及代码示例
- Node.js path.resolve([...paths])用法及代码示例
- Node.js path.basename()用法及代码示例
- Node.js path.delimiter用法及代码示例
- Node.js path.dirname(path)用法及代码示例
- Node.js path.extname(path)用法及代码示例
- Node.js path.normalize()用法及代码示例
- Node.js path.parse(path)用法及代码示例
- Node.js path.toNamespacedPath()用法及代码示例
- Node.js path.dirname()用法及代码示例
- Node.js path.format(pathObject)用法及代码示例
- Node.js path.isAbsolute(path)用法及代码示例
- Node.js path.format()用法及代码示例
- Node.js path.isAbsolute()用法及代码示例
- Node.js path.join()用法及代码示例
- Node.js path.normalize(path)用法及代码示例
- Node.js path.join([...paths])用法及代码示例
- Node.js path.parse()用法及代码示例
- Node.js path.sep用法及代码示例
- Node.js path.basename(path[, ext])用法及代码示例
- Node.js path.extname()用法及代码示例
- Node.js process.stdin用法及代码示例
- Node.js process.arch()用法及代码示例
- Node.js process.nextTick(callback[, ...args])用法及代码示例
注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 path.relative(from, to)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。