1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:build !windows && !plan9
14 func ExampleSplitList() {
15 fmt
.Println("On Unix:", filepath
.SplitList("/a/b/c:/usr/bin"))
17 // On Unix: [/a/b/c /usr/bin]
28 fmt
.Println("On Unix:")
29 for _
, p
:= range paths
{
30 rel
, err
:= filepath
.Rel(base
, p
)
31 fmt
.Printf("%q: %q %v\n", p
, rel
, err
)
36 // "/a/b/c": "b/c" <nil>
37 // "/b/c": "../b/c" <nil>
38 // "./b/c": "" Rel: can't make ./b/c relative to /a
43 "/home/arnie/amelia.jpg",
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
)
55 // input: "/home/arnie/amelia.jpg"
56 // dir: "/home/arnie/"
58 // input: "/mnt/photos/"
59 // dir: "/mnt/photos/"
61 // input: "rabbit.jpg"
64 // input: "/usr/local//go"
65 // dir: "/usr/local//"
70 fmt
.Println("On Unix:")
71 fmt
.Println(filepath
.Join("a", "b", "c"))
72 fmt
.Println(filepath
.Join("a", "b/c"))
73 fmt
.Println(filepath
.Join("a/b", "c"))
74 fmt
.Println(filepath
.Join("a/b", "/c"))
76 fmt
.Println(filepath
.Join("a/b", "../../../xyz"))
88 fmt
.Println("On Unix:")
89 fmt
.Println(filepath
.Match("/home/catch/*", "/home/catch/foo"))
90 fmt
.Println(filepath
.Match("/home/catch/*", "/home/catch/foo/bar"))
91 fmt
.Println(filepath
.Match("/home/?opher", "/home/gopher"))
92 fmt
.Println(filepath
.Match("/home/\\*", "/home/*"))
103 fmt
.Println("On Unix:")
104 fmt
.Println(filepath
.Base("/foo/bar/baz.js"))
105 fmt
.Println(filepath
.Base("/foo/bar/baz"))
106 fmt
.Println(filepath
.Base("/foo/bar/baz/"))
107 fmt
.Println(filepath
.Base("dev.txt"))
108 fmt
.Println(filepath
.Base("../todo.txt"))
109 fmt
.Println(filepath
.Base(".."))
110 fmt
.Println(filepath
.Base("."))
111 fmt
.Println(filepath
.Base("/"))
112 fmt
.Println(filepath
.Base(""))
128 fmt
.Println("On Unix:")
129 fmt
.Println(filepath
.Dir("/foo/bar/baz.js"))
130 fmt
.Println(filepath
.Dir("/foo/bar/baz"))
131 fmt
.Println(filepath
.Dir("/foo/bar/baz/"))
132 fmt
.Println(filepath
.Dir("/dirty//path///"))
133 fmt
.Println(filepath
.Dir("dev.txt"))
134 fmt
.Println(filepath
.Dir("../todo.txt"))
135 fmt
.Println(filepath
.Dir(".."))
136 fmt
.Println(filepath
.Dir("."))
137 fmt
.Println(filepath
.Dir("/"))
138 fmt
.Println(filepath
.Dir(""))
154 func ExampleIsAbs() {
155 fmt
.Println("On Unix:")
156 fmt
.Println(filepath
.IsAbs("/home/gopher"))
157 fmt
.Println(filepath
.IsAbs(".bashrc"))
158 fmt
.Println(filepath
.IsAbs(".."))
159 fmt
.Println(filepath
.IsAbs("."))
160 fmt
.Println(filepath
.IsAbs("/"))
161 fmt
.Println(filepath
.IsAbs(""))