node.js中的path.resolve方法使用说明

时间:2014-12-08    点击:180   

方法说明:

将参数 to 位置的字符解析到一个绝对路径里。

语法:

复制代码 代码如下:

path.resolve([from ...], to)

由于该方法属于path模块,使用前需要引入path模块(var path= require(“path”) )

接收参数:

from                     源路径
to                         将被解析到绝对路径的字符串

例子:

复制代码 代码如下:

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 currently in /home/myself/node, it returns
 
'/home/myself/node/wwwroot/static_files/gif/image.gif'

另一种方法是把它作为一个序列的cd命令shell。

复制代码 代码如下:

path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile')

类似于:

复制代码 代码如下:

cd foo/bar
cd /tmp/file/
cd ..
cd a/../subfile
pwd

javascript中的this详解
node.js中的path.isAbsolute方法使用说明
node.js中的path.join方法使用说明
node.js中的path.normalize方法使用说明
node.js中的path.sep方法使用说明
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved