Standard library / path/filepath

path/filepath.IsAbs()

Reports whether a path is absolute according to the host OS; Windows volume rules differ from Unix. Example uses a disposable temporary workspace. Expected stdout: 'true false\n'.

Formal Syntax & Structure

go syntaxgo
func IsAbs(path string) bool

Parameters & Attributes

NameTypeDescription
pathstringPathname interpreted according to this package.

Return Value

bool

Reports whether a path is absolute according to the host OS; Windows volume rules differ from Unix.

Working Example

Example Snippetgo
package main
import (  "fmt"  "os"  "path/filepath")
func check(e error) {  if e != nil {    panic(e)  }}func workspace() func() {  root, e := os.MkdirTemp("", "bytemind-go-")  check(e)  old, e := os.Getwd()  check(e)  check(os.Chdir(root))  return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() { defer workspace()(); fmt.Println(filepath.IsAbs("/docs"), filepath.IsAbs("docs")) }
Go Reference