27 lines
675 B
Go
27 lines
675 B
Go
package filepath
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func Filepath() {
|
|
p := filepath.Join("a", "b", "c", "d")
|
|
fmt.Println(p)
|
|
|
|
ext := filepath.Ext("main.go")
|
|
fmt.Printf("Extension is %s\n", ext)
|
|
fmt.Printf("Filename without ext is %s\n", strings.TrimSuffix("main.go", ext))
|
|
|
|
fmt.Printf("Base name is %s\n", filepath.Base("/a/b/c/file.go"))
|
|
fmt.Printf("Dirname is %s\n", filepath.Dir("/a/b/c/file.go"))
|
|
|
|
relPath, _ := filepath.Rel("/a/b", "/a/c/d/f")
|
|
fmt.Println("Rel path is", relPath)
|
|
|
|
fmt.Println("Is local?", filepath.IsLocal("filepath.go"))
|
|
fmt.Println("Is abs?", filepath.IsAbs("/a/b/c/d"))
|
|
fmt.Println("Is abs?", filepath.IsAbs("/a/b/c/d/.."))
|
|
}
|