mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
path/filepath: add example for filepath.Split
Fixes #9928 Change-Id: Iab37051078755a132f211ad48e756422f7c55a39 Reviewed-on: https://go-review.googlesource.com/5416 Reviewed-by: Minux Ma <minux@golang.org>
This commit is contained in:
parent
69275eef5e
commit
5868ce3519
1 changed files with 28 additions and 0 deletions
|
|
@ -37,3 +37,31 @@ func ExampleRel() {
|
||||||
// "/b/c": "../b/c" <nil>
|
// "/b/c": "../b/c" <nil>
|
||||||
// "./b/c": "" Rel: can't make b/c relative to /a
|
// "./b/c": "" Rel: can't make b/c relative to /a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleSplit() {
|
||||||
|
paths := []string{
|
||||||
|
"/home/arnie/amelia.jpg",
|
||||||
|
"/mnt/photos/",
|
||||||
|
"rabbit.jpg",
|
||||||
|
"/usr/local//go",
|
||||||
|
}
|
||||||
|
fmt.Println("On Unix:")
|
||||||
|
for _, p := range paths {
|
||||||
|
dir, file := filepath.Split(p)
|
||||||
|
fmt.Printf("input: %q\n\tdir: %q\n\tfile: %q\n", p, dir, file)
|
||||||
|
}
|
||||||
|
// Output:
|
||||||
|
// On Unix:
|
||||||
|
// input: "/home/arnie/amelia.jpg"
|
||||||
|
// dir: "/home/arnie/"
|
||||||
|
// file: "amelia.jpg"
|
||||||
|
// input: "/mnt/photos/"
|
||||||
|
// dir: "/mnt/photos/"
|
||||||
|
// file: ""
|
||||||
|
// input: "rabbit.jpg"
|
||||||
|
// dir: ""
|
||||||
|
// file: "rabbit.jpg"
|
||||||
|
// input: "/usr/local//go"
|
||||||
|
// dir: "/usr/local//"
|
||||||
|
// file: "go"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue