假设有一个文件路径var dir = "my/file/directory"
,我提供了一个相对文件路径var rel = "../../other/directory/myFile.js"
,如何计算真实目录:
var dir = "my/file/directory"
var rel = "../../other/directory/myFile.js"
var nDir = func(dir,rel) // returns "my/other/directory/myFile.js"
到目前为止,我发现path = require('path')
并且一直在乱用REPL中的函数。但是我无法看到relative()
函数在确定最终路径时有用...?
据我所见:
var p1 = "root"
var p2 = "my/dir/file.js"
var O = path.relative(p1,p2) //returns "../my/dir/file.js"
它正在返回相对路径......对于我来说,这应该返回"root/my/dir/file.js"
?