Combine absolute path and relative path to get a new absolute path

后端 未结 2 1243
闹比i
闹比i 2021-02-18 20:26

I\'m writing a program in which one of the components must be able to take a path it is given (such as /help/index.html, or /help/) and a relative path

2条回答
  •  走了就别回头了
    2021-02-18 21:17

    The path.Join when used with path.Dir should do what you want. See http://golang.org/pkg/path/#example_Join for an interactive example.

    path.Join(path.Dir("/help/help1.html"), "../content.txt")
    

    This will return /content.txt.

提交回复
热议问题