1
0
mirror of https://github.com/golang/go synced 2024-11-24 10:00:12 -07:00

path, path/filepath: add Join example with joined rooted path

This makes clear that Go's path.Join and filepath.Join are different
from the Python os.path.join (and perhaps others).

Requested in private mail.

Change-Id: Ie5dfad8a57f9baa5cca31246af1fd4dd5b1a64ee
Reviewed-on: https://go-review.googlesource.com/20711
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Russ Cox 2016-03-14 20:23:22 -04:00
parent 29a6149e67
commit 1f7e55e418
2 changed files with 22 additions and 1 deletions

View File

@ -54,7 +54,14 @@ func ExampleIsAbs() {
func ExampleJoin() { func ExampleJoin() {
fmt.Println(path.Join("a", "b", "c")) fmt.Println(path.Join("a", "b", "c"))
// Output: a/b/c fmt.Println(path.Join("a", "b/c"))
fmt.Println(path.Join("a/b", "c"))
fmt.Println(path.Join("a/b", "/c"))
// Output:
// a/b/c
// a/b/c
// a/b/c
// a/b/c
} }
func ExampleSplit() { func ExampleSplit() {

View File

@ -65,3 +65,17 @@ func ExampleSplit() {
// dir: "/usr/local//" // dir: "/usr/local//"
// file: "go" // file: "go"
} }
func ExampleJoin() {
fmt.Println("On Unix:")
fmt.Println(filepath.Join("a", "b", "c"))
fmt.Println(filepath.Join("a", "b/c"))
fmt.Println(filepath.Join("a/b", "c"))
fmt.Println(filepath.Join("a/b", "/c"))
// Output:
// On Unix:
// a/b/c
// a/b/c
// a/b/c
// a/b/c
}