filepath.IsAbs() Function in Golang With Examples
In Go language, path package used for paths separated by forwarding slashes, such as the paths in URLs. The filepath.IsAbs() function in Go language used to report whether the path is absolute or not. Moreover, this function is defined under the path package. Here, you need to import the “path/filepath” package in order to use these functions.
Syntax:
func IsAbs(path string) bool
Here, ‘path’ is the specified absolute or unabsolute path.
Return Value: It returns true for the absolute path else returns false.
Example 1:
package main
import (
"fmt"
"path/filepath"
)
func main() {
fmt.Println(filepath.IsAbs( "/home/gfg" ))
fmt.Println(filepath.IsAbs( ".gfg" ))
fmt.Println(filepath.IsAbs( "/gfg" ))
fmt.Println(filepath.IsAbs( ":gfg" ))
}
|
Output:
true
false
true
false
Example 2:
package main
import (
"fmt"
"path/filepath"
)
func main() {
fmt.Println(filepath.IsAbs( "/" ))
fmt.Println(filepath.IsAbs( "." ))
fmt.Println(filepath.IsAbs( ":" ))
fmt.Println(filepath.IsAbs( "/." ))
fmt.Println(filepath.IsAbs( "//" ))
fmt.Println(filepath.IsAbs( ":/" ))
}
|
Output:
true
false
false
true
true
false
Last Updated :
05 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...