Add filepath

This commit is contained in:
Sangeeth Sudheer 2024-05-03 21:44:10 +05:30
parent 5d73c57919
commit fc2dc32323
Signed by: x
GPG Key ID: F6D06ECE734C57D1
2 changed files with 30 additions and 2 deletions

26
filepath/filepath.go Normal file
View 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/.."))
}

View File

@ -36,7 +36,8 @@ package main
// import "git.sangeeth.dev/gobyexample/base64" // import "git.sangeeth.dev/gobyexample/base64"
// import "git.sangeeth.dev/gobyexample/files" // import "git.sangeeth.dev/gobyexample/files"
// import "git.sangeeth.dev/gobyexample/linefilter" // import "git.sangeeth.dev/gobyexample/linefilter"
import "git.sangeeth.dev/gobyexample/exit" // import "git.sangeeth.dev/gobyexample/exit"
import "git.sangeeth.dev/gobyexample/filepath"
func main() { func main() {
// runes.Runes() // runes.Runes()
@ -75,5 +76,6 @@ func main() {
// base64.Base64() // base64.Base64()
// files.Files() // files.Files()
// linefilter.LineFilter() // linefilter.LineFilter()
exit.Exit() // exit.Exit()
filepath.Filepath()
} }