【发布时间】:2012-10-16 05:03:29
【问题描述】:
我正在编写一个程序,其中一个组件必须能够采用给定的路径(例如/help/index.html,或/help/)和基于该位置的相对路径,(例如@ 987654324@, or sub/dir/of/help/, or help2.html) 并产生相对路径隐含的绝对路径。考虑以下目录树。
/
index.html
content.txt
help/
help1.html
help2.html
文件index.html 包含类似help/help1.html 的链接。程序通过/或/index.html,与help/help1.html结合得到/help/help1.html。
同样,文件/help/help1.html 有链接../content.txt,程序需要从该链接返回/content.txt。有没有合理的方法来做到这一点?
谢谢。 :)
编辑:感谢斯蒂芬·温伯格!对于大家from the future,这是我使用的代码。
func join(source, target string) string {
if path.IsAbs(target) {
return target
}
return path.Join(path.Dir(source), target)
}
【问题讨论】: