您的位置:首页 > Web前端 > Node.js

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

2014-12-08 00:00 921 查看
方法说明:

将参数 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: