时间:2021-07-01 10:21:17 帮助过:48人阅读
方法说明:
将参数 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