gobyexample/filepath/filepath.go

27 lines
675 B
Go
Raw Normal View History

2024-05-03 16:14:10 +00:00
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/.."))
}