二郎。使相对路径绝对

发布于 2024-12-21 23:14:27 字数 181 浏览 2 评论 0原文

我有一个相对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

謸气贵蔟 2024-12-28 23:14:27

尝试查看 mochiweb 源 它可能会有所帮助

Try to look at mochiweb sources it could be helpful

嘴硬脾气大 2024-12-28 23:14:27

正如 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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文