Standard library / path/filepath

path/filepath.IsLocal()

Checks lexical locality: nonempty, nonabsolute, and not escaping via dot-dot; Windows reserved names also matter. Symlinks are not checked. Example uses a disposable temporary workspace. Expected stdout: 'true false\n'.

Formal Syntax & Structure

go syntaxgo
func IsLocal(path string) bool

Parameters & Attributes

NameTypeDescription
pathstringPathname interpreted according to this package.

Return Value

bool

Checks lexical locality: nonempty, nonabsolute, and not escaping via dot-dot; Windows reserved names also matter.

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.IsLocal("a/b"), filepath.IsLocal("../b")) }
Go Reference