Add filepath
This commit is contained in:
26
filepath/filepath.go
Normal file
26
filepath/filepath.go
Normal file
@@ -0,0 +1,26 @@
|
||||
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/.."))
|
||||
}
|
||||
Reference in New Issue
Block a user