Standard library / path

path.IsAbs()

Reports whether a slash-separated path starts with a slash; not an OS-specific drive check. 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 slash-separated path starts with a slash; not an OS-specific drive check.

Working Example

Example Snippetgo
package main
import (  "fmt"  "os"  "path")
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(path.IsAbs("/docs"), path.IsAbs("docs")) }
Go Reference