二郎。使相对路径绝对
我有一个相对 url 和一个绝对路径,我想将其解析为绝对路径。
已尝试使用 filename:abspath("test", "/root/")。 它可以工作,但不适用于像“../”这样的相对路径 例如文件名:abspath(“../”,“/root/”)。 给出“/root/../”
有人有一个简单的解决方案吗?
I have a relative url and an absolute path and i want to resolve it to an absolute path.
Have tried using filename:abspath("test", "/root/").
and it works but not with relative paths like "../"
for example filename:abspath("../", "/root/").
gives "/root/../"
Does anyone have a simple solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试查看 mochiweb 源 它可能会有所帮助
Try to look at mochiweb sources it could be helpful
正如 filename:absname/1 的文档所述:“不会尝试创建最短的绝对名称,因为这可能会在允许链接的文件系统上给出错误的结果。”
如果您的示例 filename:abspath("../", "/root/") 会给您“/”(“优化”路径)而不是“/root/../”,它实际上可能引用了错误的路径如果“/root”是指向其他目录(例如“/foo/bar/baz”)的链接,则为目录。您确定优化的路径是您想要的吗? abspath/2 的结果是正确的,但可能不是“漂亮”。
As the documentation of filename:absname/1 says: "No attempt is made to create the shortest absolute name, because this can give incorrect results on file systems which allow links."
If your example filename:abspath("../", "/root/") would give you "/" (an "optimized" path) instead of "/root/../", it could actually refer to the wrong directory if "/root" is a link to some other directory like "/foo/bar/baz". Are you sure that an optimized path is what you want? The result from abspath/2 is correct, but perhaps not "pretty".