Skip to content

Commit 5868ce3

Browse files
committed
path/filepath: add example for filepath.Split
Fixes #9928 Change-Id: Iab37051078755a132f211ad48e756422f7c55a39 Reviewed-on: https://go-review.googlesource.com/5416 Reviewed-by: Minux Ma <[email protected]>
1 parent 69275ee commit 5868ce3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/path/filepath/example_unix_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,31 @@ func ExampleRel() {
3737
// "/b/c": "../b/c" <nil>
3838
// "./b/c": "" Rel: can't make b/c relative to /a
3939
}
40+
41+
func ExampleSplit() {
42+
paths := []string{
43+
"/home/arnie/amelia.jpg",
44+
"/mnt/photos/",
45+
"rabbit.jpg",
46+
"/usr/local//go",
47+
}
48+
fmt.Println("On Unix:")
49+
for _, p := range paths {
50+
dir, file := filepath.Split(p)
51+
fmt.Printf("input: %q\n\tdir: %q\n\tfile: %q\n", p, dir, file)
52+
}
53+
// Output:
54+
// On Unix:
55+
// input: "/home/arnie/amelia.jpg"
56+
// dir: "/home/arnie/"
57+
// file: "amelia.jpg"
58+
// input: "/mnt/photos/"
59+
// dir: "/mnt/photos/"
60+
// file: ""
61+
// input: "rabbit.jpg"
62+
// dir: ""
63+
// file: "rabbit.jpg"
64+
// input: "/usr/local//go"
65+
// dir: "/usr/local//"
66+
// file: "go"
67+
}

0 commit comments

Comments
 (0)