Documentation ¶
Overview ¶
pathelper is a golang package which provides path related helper functions.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BaseWithoutExt ¶ added in v1.0.7
BaseWithoutExt returns file base name without ext name.
Example ¶
package main import ( "fmt" "github.com/northbright/pathelper" ) func main() { file := "/tmp/input/data.json" baseWithoutExt := pathelper.BaseWithoutExt(file) fmt.Printf("%s\n", baseWithoutExt) }
Output: data
func CommandExists ¶
CommandExists returns if given command exists or not.
Example ¶
package main import ( "log" "github.com/northbright/pathelper" ) func main() { exists := pathelper.CommandExists("go") log.Printf("go exists: %v", exists) }
Output:
func CreateDirIfNotExists ¶ added in v1.0.2
CreateDirIfNotExists creates the directory if it does not exists.
Example ¶
package main import ( "fmt" "log" "github.com/northbright/pathelper" ) func main() { dir := "test/output" if err := pathelper.CreateDirIfNotExists(dir, 0755); err != nil { log.Printf("CreateDirIfNotExists error: %v", err) return } exists := pathelper.FileExists(dir) fmt.Printf("%v\n", exists) }
Output: true
func ExecDir ¶
ExecDir returns the absolute path of current executable dir. For Go 1.18 and later, you may just use os.Executable instead.
Example ¶
Run "go test -c && ./pathelper.test"
package main import ( "log" "path/filepath" "github.com/northbright/pathelper" ) func main() { // Get current executable dir. execDir, _ := pathelper.ExecDir() log.Printf("executable dir: %v", execDir) // Make an absolute path for image dir. imageDir := filepath.Join(execDir, "static", "images") log.Printf("image dir: %v", imageDir) }
Output:
func FileExists ¶
FileExists returns if given file exists or not.
Example ¶
package main import ( "log" "github.com/northbright/pathelper" ) func main() { exists := pathelper.FileExists("/tmp") log.Printf("/tmp exists: %v", exists) }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.