func Ext(path string) string
package main
import (
"fmt"
"path/filepath"
)
func main() {
fmt.Printf("No dots: %q\n", filepath.Ext("index")) // No dots: ""
fmt.Printf("One dot: %q\n", filepath.Ext("index.js")) // One dot: ".js"
fmt.Printf("Two dots: %q\n", filepath.Ext("main.test.js")) // Two dots: ".js"
}
func Join(elem ...string) string
package main
import (
"fmt"
"path/filepath"
)
func main() {
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"))
}
func Match(pattern, name string) (matched bool, err error)
package main
import (
"fmt"
"path/filepath"
)
func main() {
fmt.Println("On Unix:")
fmt.Println(filepath.Match("/home/catch/*", "/home/catch/foo"))
fmt.Println(filepath.Match("/home/catch/*", "/home/catch/foo/bar"))
fmt.Println(filepath.Match("/home/?opher", "/home/gopher"))
fmt.Println(filepath.Match("/home/\\*", "/home/*"))
}
func Split(path string) (dir, file string)
package main
import (
"fmt"
"path/filepath"
)
func main() {
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)
}
}
func SplitList(path string) []string
package main
import (
"fmt"
"path/filepath"
)
func main() {
fmt.Println("On Unix:", filepath.SplitList("/a/b/c:/usr/bin"))
}